现有数据表如下
id | text | status |
100 | weeq | 1 |
100 | weeq | 2 |
100 | weeq | 1 |
100 | weeq | 3 |
100 | weeq | 1 |
101 | weeq | 3 |
100 | weeq | 1 |
103 | weeq | 5 |
102 | weeq | 1 |
100 | weeq | 3 |
100 | weeq | 4 |
100 | weeq | 1 |
100 | weeq | 2 |
100 | weeq | 1 |
100 | weeq | 2 |
101 | weeq | 2 |
100 | weeq | 1 |
100 | weeq | 2 |
100 | weeq | 1 |
100 | weeq | 1 |
想获得id
='100' 这个用户的status
4种状态出现的次数,各位应该秒懂了吧
最重要的是我要获得的是这种状态获得的次数哦,各位是怎么解决的呢?
$status = [
'one' => 2 ,
'two' => 3,
'three' => 12,
'four' => 4 ,
];
one |
status = 1 时 |
two |
status = 2 时 |
three |
status = 3 时 |
four |
status = 4 时 |
大家都是什么样的SQL 解决的呀,膜拜最佳方案
select status,count(1) as cnt
from table
where id=100
group by status