1,decode函数
select t.user_name,
sum(decode(t.course, '语文', score,null)) as CHINESE,
sum(decode(t.course, '数学', score,null)) as MATH,
sum(decode(t.course, '英语', score,null)) as ENGLISH
from test_tb_grade t
group by t.user_name
order by t.user_name
2、if函数
select t.date,
sum(if(pay_type='1',num,0)) unionPay,
sum(if(pay_type='2',num,0)) alipay,
sum(if(pay_type='5',num,0)) activeCard,
sum(if(pay_type='7',num,0)) weChat
from t
group by t.date