题解 | #某乎问答回答过教育类问题的用户里有多少用户回答过职场类问题#
某乎问答回答过教育类问题的用户里有多少用户回答过职场类问题
http://www.nowcoder.com/practice/b02cf9ee7b9f4cdda308f8155ff3415d
# 个人认为比子查询更好理解的解法:
题目:有e的用户也有c,那就是一个“在a表也在b表”的问题
这类问题的模板解法,就是a left join b,然后把b表中匹配不上的那一部分null,用WHERE IS NOT NULL 去掉,剩下的就是“在a表也在b表”了
SELECT COUNT(t2.author_id) FROM ( SELECT DISTINCT a.author_id FROM answer_tb a JOIN issue_tb i ON a.issue_id = i.issue_id WHERE i.issue_type = "Education" ) t1 LEFT JOIN ( SELECT DISTINCT a.author_id FROM answer_tb a JOIN issue_tb i ON a.issue_id = i.issue_id WHERE i.issue_type = "Career" ) t2 ON t1.author_id = t2.author_id WHERE t2.author_id IS NOT NULL