0

假设我有下面的两个表格,我如何找到所有没有 (0) 答案的问题?

question
---------
id
content

answer
------
id
question_id
content

IE,question 1->* answers

- 编辑 -

要添加到我的问题,我将如何检索每个问题的答案计数?

4

2 回答 2

4
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
于 2012-06-30T05:36:17.923 回答
0

您可以使用以下查询找到。

Select * from question where id not in (Select question_id from answer)
于 2012-06-30T05:37:18.913 回答