【发布时间】:2012-03-29 22:47:37
【问题描述】:
在 Excel 查询中操作,我需要一个条件语句来读取一个字段,并根据该值将另一个字段设置为减号(或不减号)。
我的SQl代码如下:
SELECT "_bvSTTransactionsFull".txdate,
SUM("_bvSTTransactionsFull".debit) AS 'TOTALDebit',
SUM("_bvSTTransactionsFull".credit) AS 'TOTALCredit',
SUM("_bvSTTransactionsFull".tax_amount) AS 'TOTALTax_Amount',
SUM("_bvSTTransactionsFull".VALUE) AS 'TOTALValue',
SUM("_bvSTTransactionsFull".actualvalue) AS 'TOTALActualValue',
SUM("_bvSTTransactionsFull".actualsalesvalue) AS 'TOTALActualSalesValue',
SUM("_bvSTTransactionsFull".profit) AS 'TOTALProfit'
FROM sqlschema.dbo."_bvSTTransactionsFull" "_bvSTTransactionsFull"
WHERE ( "_bvSTTransactionsFull".txdate >=?
AND "_bvSTTransactionsFull".txdate <=? )
GROUP BY "_bvSTTransactionsFull".txdate,
"_bvSTTransactionsFull".description
HAVING ( "_bvSTTransactionsFull".description LIKE 'POS Sale' )
OR ( "_bvSTTransactionsFull".description LIKE 'POS Return' )
ORDER BY "_bvSTTransactionsFull".txdate
我需要选择查询来查看名为“ActualQuantity”的字段(在表“_bvSTTransactionsFull”中),如果该字段为 Tax_Amount = -(Tax_Amount) 或 if ActualQuantity >=0, then Tax_Amount = Tax_Amount。
请注意查询是“求和”的,所以我认为这个条件方面需要在求和发生之前处理。该查询将大约 100 000 条记录汇总为每日总数。
【问题讨论】: