1

我正在使用 DBISAM 运行以下查询

SELECT((SUM(sales.sale_amount)
+SUM(sales.vat_amount))
-SUM(payments.fee_amount)) 
AS Balance,account_details.id FROM account_details 
JOIN sales ON account_details.id = sales.account_id 
JOIN payments ON account_details.id = payments.account_id GROUP BY account_details.id

但是,有 3 种不同的销售类型 - sales.sale_type 等于 0、1 或 2。如果为 0,则应添加正的 sale_amount 和 vat_amount,否则应使用负值。

我尝试了各种

IF(sales.sale_type=0)

BEGIN
...
END
ELSE
BEGIN
...
END

无济于事,只遇到脚本甚至没有运行的错误。我不知道这些错误是否仅限于 DBISAM 还是我的一般 SQL。

任何帮助表示赞赏。

谢谢

4

1 回答 1

0

DBISAM 有 CASE 语句吗?

SELECT
  CASE WHEN sales.sale_type=0
       THEN SUM(sales.sale_amount) + SUM (sales.vat_amount) - SUM(payments.fee_amount)
       ELSE SUM(sales.sale_amount) - SUM (sales.vat_amount) + SUM(payments.fee_amount)
       END
FROM
  <blah>
于 2011-08-09T15:25:51.227 回答