2012-03-05 4 views
0

스키마 멤버 (memb_no, name, age), 책 (isbn, title, authors, publisher) 및 빌린 (memb_no, isbn, date) . 유일한 문제는 고유 한 구조를 사용하지 않아야한다는 것입니다. 고유 구조를 사용하지 않고 어떻게 다시 쓸 수 있습니까?SQL에서 고유 구문을 사용하지 않고 다시 쓰기

Select T.course_id 
From course as T 
Where unique (select R.course_id 
     From section as R 
     Where T.course_id = R.course_id and R.year = 2009); 
+1

어떤 데이터베이스를 사용하고 있습니까? – Teja

+0

스키마와 SQL이 일치하지 않습니다. –

+1

분명히 밝혀야 할 쿼리가 무엇입니까? –

답변

2

을 이미 다른 유효한 답변을 가지고, 하지만 내 선호하는 양식은 다음과 같습니다.

Select T.course_id 
From course as T 
Where (Select Count(*) 
     From section as R 
     Where T.course_id = R.course_id and R.year = 2009) = 1; 
+0

감사합니다. 도움을 주셔서 감사합니다. – Brett

1

그냥 course에 가입 서브 쿼리로 unique 쿼리를 다시 작성 :

select t.course_id 
from course as t 
join(
    select course_id 
    from section 
    where year=2009 
    group by course_id 
    having count(1)=1 
)r 
on (t.course_id=r.course_id); 
+0

감사합니다. 도움을 주셔서 감사합니다. – Brett

1

을 내 머리 위로 떨어져 :

Select T.course_id 
From course as T 
Where exists(select R.course_id 
     From section as R 
     Where T.course_id = R.course_id and R.year = 2009 
     group by course_id having count(*)=1); 
+0

감사합니다. 도움을 주셔서 감사합니다. – Brett

관련 문제