日期:2014-05-18 浏览次数:20696 次
SELECT
aa.teacher_id,
IF(SUM(CASE aa.day_num WHEN 1 THEN 1 ELSE 0 END)=0,'',SUM(CASE aa.day_num WHEN 1 THEN 1 ELSE NULL END)) AS 星期1,
IF(SUM(CASE aa.day_num WHEN 2 THEN 1 ELSE 0 END)=0,'',SUM(CASE aa.day_num WHEN 2 THEN 1 ELSE NULL END)) AS 星期2,
IF(SUM(CASE aa.day_num WHEN 3 THEN 1 ELSE 0 END)=0,'',SUM(CASE aa.day_num WHEN 3 THEN 1 ELSE NULL END)) AS 星期3
FROM (
SELECT
teacher_id,
day_num,
is_free
FROM test
WHERE is_free =1
) AS aa GROUP BY aa.teacher_id