讨论数量:
有种做大学作业的感觉。。。
select
t1.created_at,
sum(t1.total_0) as 'amount_0',
sum(t1.total_1) as 'amount_1'
from
(
select
t.created_at,
(
case t.status when 1 then t.amount end
) as 'total_0',
(
case t.status when 2 then t.amount end
) as 'total_1'
from
(
select created_at, status, sum(amount) as 'amount' from orders group by created_at, status
) as t
) as t1
group by created_at
更简洁的
select created_at,
sum(case status when 1 then amount end) as 'total_1',
sum(case status when 0 then amount end) as 'total_2'
from orders group by created_at
有种做大学作业的感觉。。。
更简洁的