mysql 一个sql 返回多个总数
ringa_lee
ringa_lee 2017-04-17 16:08:37
0
3
990

文章链接: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的,这种都没写过,疑问多多!

ringa_lee
ringa_lee

ringa_lee

全部回复(3)
阿神

all果然是关键字 换个就好了
如果是要每个status的总数select status,count(*) status_num from table where status in (1,2) group by status;

小葫芦

别名使用AS
count(*) AS number

PHPzhong

select count(*) all有问题
all是mysql的关键字,改成别的名字即可

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!