[英]Can't get this query to work in SQL (Oracle)
我試圖返回官員姓名,他們管理的酒店以及他們從以下數據庫中引用的匹配數(請參見下面的關系圖)。
我已經嘗試了以下方法,但是不起作用:
select officials.name as Official,
hotels.name as Hotel, -- hotel the official manages
count (case when officials.name = matches.referee then 1 else null end) as Matchesrefereed
from officials
left join hotels
on officials.staffid = hotels.manager
left join matches
on officials.staffid = matches.referee
where (case when hotels.name is null then '-' else hotels.name end); -- print '-' if does not manage hotel
我在選擇時遇到了一個組函數錯誤,並且最后的case
語句也不起作用。
參考關系圖:
什么是您的DBMS?
select
officials.name as Official,
nvl(hotels.name, '-') as Hotel, -- hotel the official manages
count (matches.referee) as Matchesrefereed
from officials
left join hotels on officials.staffid = hotels.manager
left join matches on officials.staffid = matches.referee
group by officials.name, nvl(hotels.name, '-')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.