2

我有一个查询如下

select
    cheque_no,
    sum(credit),
    date
from ac_cash_collection
group by 1,3;

现在我想sum(credit)从谁的记录中获取transaction_type ilike banking,但这个条件不应该适用于其他列。

4

1 回答 1

1

在 中使用case语句sum(),如下所示:

select
    cheque_no,
    sum(case when transaction_type like `%banking%` then credit else 0 end),
    date
from ac_cash_collection
group by 1,3
于 2012-08-14T00:07:30.320 回答