多表查询 子查询

多表查询

法一表联立的关键是正确连接和正确查询
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 = '浙江大学'
)
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务