需要返回两组具有两个不同where子句的数据

Bra*_*rad 3 mysql sql

我有一个跟踪交易的表.

该表设置为:

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)

Bar*_*mar 6

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)