繁体   English   中英

此sql语句引发错误

[英]This sql statement throws an error

我试图使用以下查询从表中获取计数数据

SELECT courses.published, courses.archived, courses.draft from
 (  select count(*) as published from courses where published = 't' union all
    select count(*) as draft from courses where draft = 't' union all
    select count(*) as archived from courses where archived = 't'
 ) as courses

我想要一张桌子,我可以做到这一点

$result['courses']['published']
$result['courses']['draft']
$result['courses']['archived']

但查询引发了错误

#1054 - Unknown column 'courses.archived' in 'field list'

这个怎么样:

select p.published, d.draft, a.archived
from
( select count(*) as published from courses where published = 't' ) p
cross join
( select count(*) as draft from courses where draft = 't' ) d
cross join 
( select count(*) as archived from courses where archived = 't' ) a

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM