我有一张表,这是我的销售报告,如bellow
sno order_id code value
1 1 Tax 100
2 1 Total 200
3 1 Pay 300
4 2 Tax 120
5 2 Total 230
但我想报告像贝洛一样
sno order_id tax total pay
1 1 100 200 300
2 2 120 230 0
任何人都可以帮我编写一个mysql查询来执行此操作
答案 0 :(得分:0)
select @s := @s + 1 as sno,
order_id,
max(case when code = 'tax' then value end) as tax,
max(case when code = 'total' then value end) as total,
max(case when code = 'pay' then value end) as pay
from your_table
cross join (select @s := 0) num
group by order_id