假设我有 2 个表:成员和订单(Mysql)
Members :
id | name
1 | Lee
2 | brad
Orders :
id | member_id | status (1: paid, 2: unpaid) | total
1 | 1 | 1 | 1000000
2 | 1 | 1 | 1500000
3 | 1 | 2 | 1300000
4 | 2 | 1 | 3000000
5 | 2 | 2 | 3500000
6 | 2 | 2 | 3300000
我有一个 sql 查询:
SELECT m.name,
o.member_id,
COUNT(o.id) AS number_of_order,
SUM(o.total) AS total2
FROM orders o
LEFT JOIN members m
ON o.member_id = m.id
GROUP BY o.member_id
这给了我这个:
name | number_of_order | total2
Lee | 3 | 3800000
brad | 3 | 9800000
我想要的只是这样的:
name | number_of_order | total2
| Paid Unpaid | Paid Unpaid
------------------------------------------------
Lee | 3 | 3800000
| 2 1 | 2500000 1300000
------------------------------------------------
brad | 3 | 9800000
| 1 2 | 3000000 6800000
------------------------------------------------
如何进行可以给我结果的查询?
谢谢你的时间!