有关此 JET Sql 查询的帮助

发布于 2024-09-06 04:54:50 字数 328 浏览 7 评论 0原文

我需要帮助来执行此查询选择。

例如,我有以下字段:

  • idInvoice
  • 日期
  • 金额

根据日期,我需要将字段“金额”乘以 x 数字或其他数字。

例如,如果日期小于 01/01/2010 则乘以 20 。但如果它是大数或等于乘以 35

Select idInvoice, date, amount, amount * varNumber from invoices

I need help to do this query select.

for example I have these fields:

  • idInvoice
  • date
  • amount

Depending of the date I need multiply the field "amount" for x number or other one.

For example, if the date is less 01/01/2010 to multiply for 20 . But if it is major or equal to multiply for 35

Select idInvoice, date, amount, amount * varNumber from invoices

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幽梦紫曦~ 2024-09-13 04:54:50

假设您的日期字段不允许 Null,您应该能够使用 IIf 表达式进行计算。

SELECT
    idInvoice,
    [date],
    amount,
    IIf([date] < #2010/01/01#, amount * 20, amount * 30) AS extended_amount
FROM invoices;

请注意,我将日期字段名称括在方括号中,因为日期是 Access 中的保留字。方括号向数据库引擎发出信号,表明您需要名为“date”的字段而不是 Date() 函数。

Access 日期字段还包含时间部分。因此,对于今年年初午夜之前的任何值,该查询都会将金额乘以 20。这意味着对于 2010 年 1 月 1 日凌晨 1:00,金额将乘以 30。如果这不是您想要的,请更改 IIf 表达式。

如果您的 [日期] 字段允许 Null,请查看 Access 的 Nz() 函数帮助。

Assuming your date field does not allow Nulls, you should be able to use an IIf expression for your calculation.

SELECT
    idInvoice,
    [date],
    amount,
    IIf([date] < #2010/01/01#, amount * 20, amount * 30) AS extended_amount
FROM invoices;

Notice I enclosed the date field name in square brackets because date is a reserved word in Access. The square brackets signal the database engine that you want a field named "date" rather than the Date() function.

Also Access date fields include a time component. So that query will multiple amount by 20 for any values earlier than midnight at the start of this year. That means for 1/1/2010 at 1:00 AM, amount would be multiplied by 30. If that isn't what you want, change the IIf expression.

And if your [date] field allows Nulls, look at Access' help for the Nz() function.

橘虞初梦 2024-09-13 04:54:50

或者

SELECT 
    idInvoice, 
    [date], 
    amount, 
    amount *IIf([date] < #2010/01/01#, 20, 30) AS extended_amount 
FROM invoices; 

or

SELECT 
    idInvoice, 
    [date], 
    amount, 
    amount *IIf([date] < #2010/01/01#, 20, 30) AS extended_amount 
FROM invoices; 
迷离° 2024-09-13 04:54:50
Select idInvoice, date, amount, 
amount * case when date<'20100101' then 20 else 35 end as amount from invoices 
Select idInvoice, date, amount, 
amount * case when date<'20100101' then 20 else 35 end as amount from invoices 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文