아래 두 표가 있다고 말하면, 답변이없는 모든 질문을 어떻게 찾을 수 있습니까?아이들이없는 일대 다 부모를 찾으십시오.
question
---------
id
content
및
answer
------
id
question_id
content
즉, question 1->* answers
- 편집 -
어떻게 각 질문에 대한 답변의 수를 검색하는 것, 내 질문에 추가하려면? 편집 질문에
아래 두 표가 있다고 말하면, 답변이없는 모든 질문을 어떻게 찾을 수 있습니까?아이들이없는 일대 다 부모를 찾으십시오.
question
---------
id
content
및
answer
------
id
question_id
content
즉, question 1->* answers
- 편집 -
어떻게 각 질문에 대한 답변의 수를 검색하는 것, 내 질문에 추가하려면? 편집 질문에
select * from question q where not exists (select 1 from answer a where a.question_id=q.id)
답 :
select q.id, content, count(a.id)
from question q
left outer join answer a
on q.id = a.question_id
group by q.id
당신이 쿼리 아래 사용으로 찾을 수 있습니다.
Select * from question where id not in (Select question_id from answer)
안녕하세요! 필자는 대답을 편집 했으므로 추가 된 요구 사항을 확인할 수 있습니까? – zsquare
@zsquare 좀 더 자세한 정보를 제공해주십시오. –
하위 쿼리 결과를 줄이기 위해'in (Select an distinct from question_id) from answer '라고 말할 수 있습니다. –
안녕하세요! 필자는 대답을 편집 했으므로 추가 된 요구 사항을 확인할 수 있습니까? – zsquare