Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要一份报告,其中包含按日期分组的列具有的不同值的计数,每个日期一个输出行。
表格列是日期、位置 ID (var) 和评级 (var)。评级只能有四个值之一,“A”、“B”、“C”或空/空白。使用此选择,我可以在每个日期每个值获取一行,但是如何获取每个日期在同一行上的所有四个值的计数?
SELECT date, rating, count(rating) AS ratings FROM table GROUP BY date, rating
与布尔值一起使用SUM,如下所示:
SUM
SELECT date, SUM(rating = 'A') AS count_A, SUM(rating = 'B') AS count_B, SUM(rating = 'C') AS count_C, SUM(rating = '' OR rating IS NULL) AS count_blank FROM yourtable GROUP BY date