我有两张桌子,想要解决问题:
表:问题
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
可能有人知道如何计算已解决的问题(solve_answer_id> 0)来回答created_by user:953?
谢谢!
P.S结果将是:1对于上述情况(solve_answer_id = 49)...
答案 0 :(得分: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