在MySql查询的帮助下,我想得到如下结果:
date total read unread
2018-01-31 8 4 4
2018-02-01 2 2 0
Run Code Online (Sandbox Code Playgroud)
试试这个:
SELECT date, COUNT(*) as total,
SUM(CASE WHEN read = 1 THEN 1 ELSE 0) as read
SUM(CASE WHEN read = 0 THEN 1 ELSE 0) as unread
FROM yourtable
GROUP BY date
Run Code Online (Sandbox Code Playgroud)