2014-11-05 53 views
-1

我有兩個表,想指望解決的問題:盤點記錄加入的問題和答案表

表:問題

id title solved_answer_id 
174 Title1 0 
172 Title2 45 
173 Title3 0 
175 Title4 49 

表:回答

id created_by question_id 
49 953  175 
47 907  173 
48 906  173 
46 907  172 
45 906  172 

可能有人知道如何計算已解決的問題(resolved_answer_id> 0)以獲得答案created_by user:953?

謝謝!

P.S結果將是:1以上的情況下(solved_answer_id = 49)...

+0

我已經嘗試了很多! – user889349 2014-11-05 14:49:21

+0

=))好吧,如果你這麼說... – 2014-11-05 15:03:09

回答

1
select count(q.id) as cnt 
from questions q 
join answers a on a.question_id = q.id 
where q.solved_answer_id > 0 
and a.created_by = 953 
+0

created_by應該在答案表中... – user889349 2014-11-05 14:41:00

+0

非常感謝!上面的剪切真的幫助我! – user889349 2014-11-05 14:52:31