我想在我所在的位置显示这样的GROUP
数据DATE
:
Date Star1 Star2 Star3 Star4 Star5
2012-10-25 null null null 1 1
我的当前表有三 (3) 列,显示:
ID DATE RATING
5 2012-10-25 4
6 2012-10-25 5
我正在使用此查询来尝试实现上述数据:
SELECT
DATE,
CASE
WHEN RATING = 1 THEN 1
ELSE NULL
END AS STAR1,
CASE
WHEN RATING = 2 THEN 1
ELSE NULL
END AS STAR2,
CASE
WHEN RATING = 3 THEN 1
ELSE NULL
END AS STAR3,
CASE
WHEN RATING = 4 THEN 1
ELSE NULL
END AS STAR4,
CASE
WHEN RATING = 5 THEN 1
ELSE NULL
END AS STAR5
FROM
table1
WHERE
DATE = '2012-10-25'
GROUP BY DATE
ORDER BY DATE
这只会吐出一个评级:
Date Star1 Star2 Star3 Star4 Star5
2012-10-25 null null null null 1
就像它不是在日期上进行分组一样,我该如何实现呢?