我有一张桌子
________________________________________________________________________________
| Message |
|_______________________________________________________________________________|
| ID(INT) | Text(TEXT) |read(TINYINT(0/1)) |deleted(TINYINT(0/1))| User_id |
| 1 | How Are You?| 0 | 0 | 6 |
| 2 | Fine | 0 | 1 | 4 |
| 3 | Message 3 | 1 | 0 | 6 |
| 4 | Message 4 | 0 | 1 | 6 |
| 5 | Message 5 | 1 | 0 | 5 |
|_________|_____________|___________________|_____________________|_____________|
现在我想选择 user_id=6 的消息,并分别选择 read=0 和 read=1 的列数。我知道这可以通过命令分组来完成,我目前使用两个 sql 查询来完成。可能有人加入他们合二为一
select message,count(*) from message where User_id=6 and read=0 group by id;//for unread message
select message,count(*) from message where User_id=6 and read=1 group by id;//for read message