多表查询 子查询

多表查询

法一表联立的关键是正确连接和正确查询
select q.device_id, q.question_id, q.result
from question_practice_detail as q
inner join user_profile as u
on q.device_id = u.device_id
where u.university = '浙江大学';

法二子查询的关键是锁定两张表的相同列,然后利用筛选条件选出要找的行的位置,最后利用位置选中另一张表中的数据
select device_id, question_id, result 
from question_practice_detail
where device_id in (
    select device_id
    from user_profile
    where university = '浙江大学'
)
全部评论

相关推荐

不愿透露姓名的神秘牛友
06-30 18:19
点赞 评论 收藏
分享
06-05 19:46
已编辑
武汉大学 后端
点赞 评论 收藏
分享
每晚夜里独自颤抖:这个在牛客不是老熟人了吗
点赞 评论 收藏
分享
ohs的小木屋:比不少实习待遇高了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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