zoukankan      html  css  js  c++  java
  • 数据库常用面试题

    解答: 

    --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

  • 相关阅读:
    未在本地计算机上注册“Microsoft.Jet.OleDb.4.0”提供程序
    GridView选中行变色
    GridView 添加/删除行
    Session、Cookie、Application、ViewState和Cache 这四者的区别
    后台动态给textbox的字体颜色赋值
    JS来判断文本框内容改变事件
    gridview JS控件赋值后如何取值
    c#如何把8位字符串转换成日期格式
    从今天起,热爱生活
    杂得得杂
  • 原文地址:https://www.cnblogs.com/jasonjiang/p/1763779.html
Copyright © 2011-2022 走看看