我有一个跟踪交易的表.
该表设置为:
transactions:
id, account_id, budget_id, points, type
Run Code Online (Sandbox Code Playgroud)
我需要返回每个budget_id的点数之和,其中type ='allocation'和point之和,其中type ='issue'
我知道如何在一个查询中执行每个操作,但不能同时执行.
预期结果集:
budget_id allocated issued
434 200000 100
242 100000 5020
621 45000 3940
Run Code Online (Sandbox Code Playgroud)
SELECT budget_id,
SUM(IF(type = 'allocation', points, 0)) AS allocated,
SUM(IF(type = 'issue', points, 0)) AS issued
FROM transactions
GROUP BY budget_id
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
255 次 |
| 最近记录: |