2013-05-10 2 views
0

임, 그들이 관리하는 호텔과 그들이 아래의 데이터베이스에서 주심을 한 경기의 수 (아래 관계형 그림 참조)이 쿼리는 SQL (오라클)에서 작동하도록 가져올 수 없습니다.는 공무원의 이름을 반환하려고

나는 다음을 시도했지만 작동하지 않습니다 :

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 문은 작동하지 않습니다. 참조에서

관계 다이어그램 :

enter image description here

답변

1

당신의 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, '-') 
+0

DBMS는 오라클입니다. – Martin

+0

이 하나 –

+0

그것은 가끔 공식의 중복 레코드를 반환합니다 제외하고 거의 맞습니다 (을 잘못 호텔 관리에 할당) 시도 @Tangler. @Tangler 당신은 몇 가지 예제 데이터를 제공 할 수 – Martin

관련 문제