题解 21 | #浙江大学用户题目回答情况#

【分类】:子查询、多表连接

分析思路

select 查询结果 [设备ID;题目ID;答题结果]
from 从哪张表中查询数据[多个join连接的表]
where 查询条件 [浙江大学用户]

扩展

前往查看:MySQL 嵌套子查询

求解代码

方法一:

in 子查询

#查看所有来自浙江大学的用户题目回答明细情况
select
    device_id,
    question_id,
    result
from user_profile
join question_practice_detail using(device_id)
where device_id in(
    #统计来自浙江大学的用户
    select
        device_id
    from user_profile
    where university = '浙江大学'
)

方法二

select 
    a.device_id,
    question_id,
    result
from user_profile a, question_practice_detail b
where a.device_id = b.device_id
and university = '浙江大学'
全部评论

相关推荐

用微笑面对困难:只要你保证项目和获奖都是真的就行尤其是“对战,总负责人”啊这些套职,基本上队员,打杂的都这么写
点赞 评论 收藏
分享
评论
28
20
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务