Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 此sql语句引发错误_Php_Mysql_Sql - Fatal编程技术网

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中提供的信息相对应的所需结果集。