簡體   English   中英

無法使該查詢在SQL(Oracle)中工作

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM