| 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 解决的呀,膜拜最佳方案
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
select status,count(1) as cnt
from table
where id=100
group by status
SQL没有设置键值的办法,本身只是查出数据而已。变成你希望的格式是需要自己处理的,有些框架已经封装好了,像tp可以用getfield()