2021校招滴滴笔试sql
题目描述
原表:
id amount,order_type(不止下面三种车型,但是只取下面三种车型),payment_chnl(不止下面三种支付方式,需要取全部的支付方式)
输出样例:
尝试解答
select
sum(case when order_type=‘wechat’ then amount else 0 end) as wechat,
sum(case when order_type=‘alipay’ then amount else 0 end) as alipay,
sum(case when order_type=‘cash’ then amount else 0 end) as cash,
sum(case when order_type=‘other’ then amount else 0 end) as other
from
table
where order_type in (‘shunfengche’,‘kuaiche’,‘pinche’)
group by order_type