首先我要確認這是一個完善且正確的查詢。
其次,我想在某種程度上,甚至在沒有客人蔘加演出了日期加盟:查詢以獲取所有參加日期的訪客
我想所有篩選日期,其中location = "Studio"
,有跡象表明,有位置工作室5個日期,所以我希望5個結果。但我只得到4,因爲只有4天有賓客參加。如何重寫我的查詢,以顯示在沒有客人蔘加過(第五行)
SCHEMA
screening_date_guest(guest_id, screening_date_id, attending)
user_guest_group(guest_id, user_id, group_id)
注意
- 客人只能屬於一個GROUP_ID天但多個user_id的
- 參加是一個布爾值
查詢
select
count(distinct(sdg.guest_id)),
`date`
from
screening_date_guest sdg
inner join
user_guest_group ugs on ugs.guest_id = sdg.guest_id
inner join
screening_dates sd on sd.id = sdg.screening_date_id
where
attending = 1
AND
sd.location = 'Studio'
group by
`date`
order by sd.`date`
我現在的RS是這樣的:
15, 2015-05-18 00:00:00
4, 2015-05-19 00:00:00
2, 2015-05-20 00:00:00
4, 2015-05-21 00:00:00
應該有另一行:
5, 2015-05-22 00:00:00
我試圖做左加入,但仍最終得到4排。
如果您在[SQL FIDDLE](http://sqlfiddle.com/) – 1000111