题解 | #某乎问答回答过教育类问题的用户里有多少用户回答过职场类问题#
某乎问答回答过教育类问题的用户里有多少用户回答过职场类问题
http://www.nowcoder.com/practice/b02cf9ee7b9f4cdda308f8155ff3415d
基于我的做法其他人没实现过,我把代码实现写个题解吧
连接的确是很快想到的方法,但我这个是不需要用到Join这个关键字
实现逻辑大致是,筛选出教育类和职业类的记录(必定要用distinct确保每个用户每个类型只会有一条)
然后以用户为分组,做排名记录。若有第二名以上的,即为满足问题需求的用户
with ep_info_tb as ( select distinct author_id, issue_type from answer_tb left join issue_tb using(issue_id) where issue_type = 'Education' or issue_type = 'Career' ) select count(author_id) from ( select author_id, max(number) as cnt from ( select author_id, issue_type, row_number() over(partition by author_id) as number from ep_info_tb ) t group by author_id having cnt >= 2 ) t2