文章链接:https://segmentfault.com/a/11...
说道:
一个sql 返回多个总数
$sql = "select count(*) all, " ;
$sql .= " count(case when status = 1 then status end) status_1_num, ";
$sql .= " count(case when status = 2 then status end) status_2_num ";
$sql .= " from table_name";
疑问:这条sql是否有问题,我去尝试了,报错,以前类似查询我都用多天sql的,这种都没写过,疑问多多!
all果然是關鍵字 換個就好了
如果是要每個status的總數
select status,count(*) status_num from table where status in (1,2) group by status;
別名使用AS
count(*) AS number
select count(*) all有問題
all是mysql的關鍵字,改成別的名字即可