• 数据库常用面试题


    解答: 

    --1
    select * from students where sid in
    (select r_sid from sresult where r_cid=(select cid from Course where cname='税收基础'))
    --2
    select * from students where sid in
    (select r_sid from SResult where r_cid =2)
    --3
    select * from students where sid not in
    (select r_sid from SResult where r_cid =5)
    --4
    select * from dbo.Students where sid in
    (
    select r_sid from  SResult group by r_sid having count(*) =
    (select count(*) from Course)
    )
    --5
    select count(distinct r_sid) from sresult
    --select count(*) from
    --(select r_sid from sresult
    --group by r_sid) a
    --6

    select * from dbo.Students where sid in
    (
    select r_sid from  SResult group by r_sid having count(*) >5
    )

    解答:

    --1
    select * from students where st_id in
    (select r_stid from Results where r_tid not in
    (select t_id from dbo.Teachers where t_name='李明'))
    --2
    select a.st_name,b.fenshu from Students a,
    (select r_stid,avg(r_fenshi) as fenshu from Results where r_fenshi <60 group by r_stid having count(*) >=2) b
    where a.st_id = b.r_stid
    --3

    select * from Students where st_id in
    (
    select r_stid from Results where r_tid in
    (select t_id from Teachers where t_lesson='数学' or t_lesson='英语')
    group by r_stid having count(*) =2
    )
    --4
    select r_stid from Results
    where r_fenshi >
    (select r_fenshi from dbo.Results where r_tid='t001' and r_stid='st002')
    and r_tid ='t001'

    --5
    --select * from dbo.Students
    --select * from dbo.Teachers
    select * from (select * from Results where r_tid ='t001') a,(select * from Results where r_tid ='t002') b
    where
     a.r_stid =b.r_stid
    and a.r_fenshi >b.r_fenshi

    --select * from Results where (r_tid ='t001' or r_tid ='t002') and  r_stid in ('st001','st002','st003') order by r_stid
    --select * from Results where r_tid ='t002' order by r_stid

  • 相关阅读:
    时间选择框(可用于Form)
    点击复制指定内容
    ajax中多个模板之间套用ajax
    Java学习路径
    Windows平台安装Python
    Python语法-第2关
    Python语法-第1关
    Python语法-第0关
    图像识别
    wx:for用法
  • 原文地址:https://www.cnblogs.com/jasonjiang/p/1763779.html
Copyright © 2020-2023  润新知