[英]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.