问题描述:要求一个语句从study,DICT 表中取出如表三所列格式数据
study表
DICT表
表三
答案:SQL:
SELECT Deptname,
MAX(CASE WHEN Mon = '一月份' THEN value ELSE null END) AS 一月份,
MAX(CASE WHEN Mon = '二月份' THEN value ELSE null END) AS 二月份,
MAX(CASE WHEN Mon = '三月份' THEN value ELSE null END) AS 三月份
FROM `study` as a right join `DICT` as b on a.dept=b.Dept group by Deptname