计算记录连接问题和答案表的记录 [英] count records joining questions and answers tables
本文介绍了计算记录连接问题和答案表的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个表格,想算一下已解决的问题:
I have two tables and would like to count solved questions:
表格:问题
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
也许有人知道如何计算用户为953创建的答案的已解决问题(solved_answer_id> 0)?
May be someone know how to count solved questions (solved_answer_id>0) for answer created_by user: 953?
谢谢!
P.S结果将是:上面的情况是1(solved_answer_id = 49)...
P.S Result will be: 1 for the case above (solved_answer_id = 49)...
推荐答案
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
这篇关于计算记录连接问题和答案表的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文