Php 此sql语句引发错误
我尝试使用以下查询从表中获取计数数据Php 此sql语句引发错误,php,mysql,sql,Php,Mysql,Sql,我尝试使用以下查询从表中获取计数数据 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(*)
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
删除
课程。
从顶部的“已发布、存档和草稿”前面删除。@IanSellar仍然是相同的错误您在将它们与组合时,从内部查询中只返回一列(三行)UNION@davek我怎样才能实现我所描述的?如果你愿意,考虑以下简单的两步行动:1。如果您还没有这样做,请提供适当的DDL(和/或SQLFIDLE),以便我们可以更轻松地复制问题。2.如果尚未这样做,请提供与步骤1中提供的信息相对应的所需结果集。