我有两个mysql表:
**tbl_questions**
id user_id title solved_answer
1 1 Title1 0 // Not solved question
2 2 Title2 3 // Solved question
**tbl_answers**
id user_id title
1 3 Answer1
2 4 Answer2
3 4 Answer3
我需要通过user_id = 4
计算已解决答案的问题数量我该怎么做?
答案 0 :(得分:1)
此查询将返回所有已解决的答案(考虑到您使用答案表中的答案ID更新问题)
select * from question q
join answer a on q.solved_answer = a.id
这个将搜索特定用户的特定问题的答案:
select * from question q
join answer a on q.solved_answer = a.id
where a.user_id=4