SQL笔试50题(下)

Wesley13
• 阅读 472

正文共:4832 字 22 图  预计阅读时间:13 分钟

前文推送

  1. MIT线性代数相关资源汇总

  2. SQL Server入门

  3. Transact-SQL基础(上)

  4. Transact-SQL基础(下)

  5. SQL笔试50题(上)

本文目录:

  • 5.2 sql笔试50题后25题

5. SQL面试50题

  • 26.查询每门课程被选修的学生数

    1
    
     
    
    
    
    -- 此题只使用Score单表也可以
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    select 
    
     
    
    
    
    
    
     
    
    
    
    3  c.cname,
    
     
    
    
    
    
    
     
    
    
    
    4  
    
     
    
    
    
    count(s.sid) 
    
     
    
    
    
    as 
    
     
    
    
    
    '选课人数'
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    from Score s, Course c
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    where s.cid = c.cid
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    group 
    
     
    
    
    
    by c.cname
    

SQL笔试50题(下)

sql50_26

  • 27.查询出只选修了一门课程的全部学生的学号和姓名

    1
    
     
    
    
    
    -- 此题可以在第三题基础上增加限制
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    -- 没有这样的学生。
    
     
    
    
    
    
    
     
    
    
    
    3
    
     
    
    
    
    SELECT a.sid,a.sname,
    
     
    
    
    
    
    
     
    
    
    
    4
    
     
    
    
    
    count(b.cid) 
    
     
    
    
    
    as 
    
     
    
    
    
    '选课数'
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    FROM Student a
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    left 
    
     
    
    
    
    join Score b
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    on a.sid = b.sid
    
     
    
    
    
    
    
     
    
    
    
    8
    
     
    
    
    
    group 
    
     
    
    
    
    by a.sid,a.sname
    
     
    
    
    
    
    
     
    
    
    
    9
    
     
    
    
    
    having 
    
     
    
    
    
    count(b.cid) = 
    
     
    
    
    
    1
    
     
    
  • 28.查询男生、女生人数

    1
    
     
    
    
    
    SELECT
    
     
    
    
    
    
    
     
    
    
    
    2  ssex,
    
     
    
    
    
    
    
     
    
    
    
    3  
    
     
    
    
    
    count(
    
     
    
    
    
    sid) 
    
     
    
    
    
    as 
    
     
    
    
    
    '人数'
    
     
    
    
    
    
    
     
    
    
    
    4
    
     
    
    
    
    FROM Student
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    GROUP 
    
     
    
    
    
    BY ssex
    
     
    
  • 29.查询名字中含有"风"字的学生信息

    1
    
     
    
    
    
    SELECT
    
     
    
    
    
    
    
     
    
    
    
    2  
    
     
    
    
    
    sid,
    
     
    
    
    
    
    
     
    
    
    
    3  sname,
    
     
    
    
    
    
    
     
    
    
    
    4  sage,
    
     
    
    
    
    
    
     
    
    
    
    5  ssex
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    FROM Student
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    WHERE sname 
    
     
    
    
    
    like N
    
     
    
    
    
    '%风%'  
    
     
    
    
    
    --编码原因加了N,视实际情况而定
    

SQL笔试50题(下)

sql50_29

  • 30.查询同名同性学生名单,并统计同名人数

    1
    
     
    
    
    
    -- 根据姓名和性别分组即可
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    SELECT
    
     
    
    
    
    
    
     
    
    
    
    3  sname,
    
     
    
    
    
    
    
     
    
    
    
    4  ssex,
    
     
    
    
    
    
    
     
    
    
    
    5  
    
     
    
    
    
    count(
    
     
    
    
    
    sid)
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    FROM Student
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    GROUP 
    
     
    
    
    
    BY sname,ssex
    

SQL笔试50题(下)

sql50_30

  • 31.查询1990年出生的学生名单(注:Student表中Sage列的类型是datetime)

    1
    
     
    
    
    
    SELECT
    
     
    
    
    
    
    
     
    
    
    
    2  *
    
     
    
    
    
    
    
     
    
    
    
    3
    
     
    
    
    
    FROM Student
    
     
    
    
    
    
    
     
    
    
    
    4
    
     
    
    
    
    WHERE 
    
     
    
    
    
    year(sage) = 
    
     
    
    
    
    1990
    

SQL笔试50题(下)

sql50_31

  • 32.查询每门课程的平均成绩,结果按平均成绩升序排列,平均成绩相同时,按课程号降序排列

    1
    
     
    
    
    
    -- 同第十九题
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
    3  s.cid,
    
     
    
    
    
    
    
     
    
    
    
    4  c.cname,
    
     
    
    
    
    
    
     
    
    
    
    5  
    
     
    
    
    
    AVG(s.score) 
    
     
    
    
    
    as mean_score
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    from Score s, Course c
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    where s.cid = c.cid
    
     
    
    
    
    
    
     
    
    
    
    8
    
     
    
    
    
    group 
    
     
    
    
    
    by s.cid,c.cname
    
     
    
    
    
    
    
     
    
    
    
    9
    
     
    
    
    
    order 
    
     
    
    
    
    by 
    
     
    
    
    
    AVG(s.score) 
    
     
    
    
    
    asc, s.cid 
    
     
    
    
    
    desc
    

SQL笔试50题(下)

sql50_32

  • 33.查询不及格的课程,并按课程号从大到小排列

     1
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
     2  sc.cid,
    
     
    
    
    
    
    
     
    
    
    
     3  s.sname,
    
     
    
    
    
    
    
     
    
    
    
     4  c.cname,
    
     
    
    
    
    
    
     
    
    
    
     5  sc.score
    
     
    
    
    
    
    
     
    
    
    
     6
    
     
    
    
    
    from Score sc, Course c, Student s
    
     
    
    
    
    
    
     
    
    
    
     7
    
     
    
    
    
    where sc.cid = c.cid
    
     
    
    
    
    
    
     
    
    
    
     8
    
     
    
    
    
    and sc.sid = s.sid
    
     
    
    
    
    
    
     
    
    
    
     9
    
     
    
    
    
    and sc.score < 
    
     
    
    
    
    60
    
     
    
    
    
    
    
     
    
    
    
    10
    
     
    
    
    
    order 
    
     
    
    
    
    by sc.cid 
    
     
    
    
    
    desc
    

SQL笔试50题(下)

sql50_33

  • 34.查询课程编号为"01"且课程成绩在60分以上的学生的学号和姓名

    1
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
    2  s.sid,
    
     
    
    
    
    
    
     
    
    
    
    3  s.sname,
    
     
    
    
    
    
    
     
    
    
    
    4  sc.score
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    from Score sc, Course c, Student s
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    where sc.cid = c.cid
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    and sc.sid = s.sid
    
     
    
    
    
    
    
     
    
    
    
    8
    
     
    
    
    
    and sc.cid = 
    
     
    
    
    
    '01'
    
     
    
    
    
    
    
     
    
    
    
    9
    
     
    
    
    
    and sc.score > 
    
     
    
    
    
    60
    

SQL笔试50题(下)

sql50_34

  • 35.查询所有学生的课程及分数情况

     1
    
     
    
    
    
    -- 查看每个人的年龄,性别,三门课成绩
    
     
    
    
    
    
    
     
    
    
    
     2
    
     
    
    
    
    -- 就是在开头使用的用于便捷判断结果的 all_info
    
     
    
    
    
    
    
     
    
    
    
     3
    
     
    
    
    
    -- 利用了pivot来行转列
    
     
    
    
    
    
    
     
    
    
    
     4
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
     5
    
     
    
    
    
    sid,sname,sage,ssex,[语文],[数学],[英语]
    
     
    
    
    
    
    
     
    
    
    
     6
    
     
    
    
    
    from
    
     
    
    
    
    
    
     
    
    
    
     7(
    
     
    
    
    
    
    
     
    
    
    
     8
    
     
    
    
    
    select a.sid,a.sname,a.sage,a.ssex,c.cname,b.score
    
     
    
    
    
    
    
     
    
    
    
     9  
    
     
    
    
    
    from Student a
    
     
    
    
    
    
    
     
    
    
    
    10  
    
     
    
    
    
    left 
    
     
    
    
    
    join Score b 
    
     
    
    
    
    
    
     
    
    
    
    11  
    
     
    
    
    
    on a.sid=b.sid
    
     
    
    
    
    
    
     
    
    
    
    12  
    
     
    
    
    
    left 
    
     
    
    
    
    join Course c
    
     
    
    
    
    
    
     
    
    
    
    13  
    
     
    
    
    
    on b.cid = c.cid
    
     
    
    
    
    
    
     
    
    
    
    14) source_table
    
     
    
    
    
    
    
     
    
    
    
    15
    
     
    
    
    
    pivot(
    
     
    
    
    
    
    
     
    
    
    
    16  
    
     
    
    
    
    sum(score) 
    
     
    
    
    
    for
    
     
    
    
    
    
    
     
    
    
    
    17cname 
    
     
    
    
    
    in (
    
     
    
    
    
    
    
     
    
    
    
    18  [语文],[数学],[英语]
    
     
    
    
    
    
    
     
    
    
    
    19)
    
     
    
    
    
    
    
     
    
    
    
    20     ) t
    

SQL笔试50题(下)

sql50_35

  • 36.查询任何一门课程成绩在70分以上的姓名、课程名称和分数

    1
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
    2  s.sname,
    
     
    
    
    
    
    
     
    
    
    
    3  c.cname,
    
     
    
    
    
    
    
     
    
    
    
    4  sc.score
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    from Score sc, Course c, Student s
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    where sc.cid = c.cid
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    and sc.sid = s.sid
    
     
    
    
    
    
    
     
    
    
    
    8
    
     
    
    
    
    and sc.score > 
    
     
    
    
    
    70
    

SQL笔试50题(下)

sql50_36

  • 37.查询课程名称为"数学",且分数低于60的学生姓名和分数

    1
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
    2  s.sname,
    
     
    
    
    
    
    
     
    
    
    
    3  sc.score
    
     
    
    
    
    
    
     
    
    
    
    4
    
     
    
    
    
    from Score sc, Course c, Student s
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    where sc.cid = c.cid
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    and sc.sid = s.sid
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    and sc.score < 
    
     
    
    
    
    60
    
     
    
    
    
    
    
     
    
    
    
    8
    
     
    
    
    
    and c.cname = N
    
     
    
    
    
    '数学'
    

SQL笔试50题(下)

sql50_37

  • 38.查询课程编号为03且课程成绩在80分以上的学生的学号和姓名

     1
    
     
    
    
    
    -- 和第三十四题是一样的,混进来的题目?
    
     
    
    
    
    
    
     
    
    
    
     2
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
     3  s.sid,
    
     
    
    
    
    
    
     
    
    
    
     4  s.sname,
    
     
    
    
    
    
    
     
    
    
    
     5  sc.score
    
     
    
    
    
    
    
     
    
    
    
     6
    
     
    
    
    
    from Score sc, Course c, Student s
    
     
    
    
    
    
    
     
    
    
    
     7
    
     
    
    
    
    where sc.cid = c.cid
    
     
    
    
    
    
    
     
    
    
    
     8
    
     
    
    
    
    and sc.sid = s.sid
    
     
    
    
    
    
    
     
    
    
    
     9
    
     
    
    
    
    and sc.cid = 
    
     
    
    
    
    '03'
    
     
    
    
    
    
    
     
    
    
    
    10
    
     
    
    
    
    and sc.score > 
    
     
    
    
    
    80
    

SQL笔试50题(下)

sql50_38

  • 39.求每门课程的学生人数

    1
    
     
    
    
    
    -- 混进来的题目?
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    select 
    
     
    
    
    
    
    
     
    
    
    
    3  cid,
    
     
    
    
    
    
    
     
    
    
    
    4  
    
     
    
    
    
    count(
    
     
    
    
    
    sid)
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    from Score
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    group 
    
     
    
    
    
    by cid
    
     
    
  • 40.查询选修“张三”老师所授课程的学生中,成绩最高的学生姓名及其成绩

    1
    
     
    
    
    
    -- 利用 top
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    select 
    
     
    
    
    
    
    
     
    
    
    
    3   top 
    
     
    
    
    
    1 s.sid, s.sname, sc.score
    
     
    
    
    
    
    
     
    
    
    
    4
    
     
    
    
    
    from Score sc, Course c, Teacher t, Student s
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    where sc.cid = c.cid
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    and c.tid=t.tid
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    and sc.sid = s.sid
    
     
    
    
    
    
    
     
    
    
    
    8
    
     
    
    
    
    and t.tname=N
    
     
    
    
    
    '张三'
    

SQL笔试50题(下)

sql50_40

  • 41.查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩

     1
    
     
    
    
    
    -- 同表级联查询
    
     
    
    
    
    
    
     
    
    
    
     2
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
     3  
    
     
    
    
    
    distinct
    
     
    
    
    
    
    
     
    
    
    
     4  s1.sid,
    
     
    
    
    
    
    
     
    
    
    
     5  s1.cid,
    
     
    
    
    
    
    
     
    
    
    
     6  s1.score
    
     
    
    
    
    
    
     
    
    
    
     7
    
     
    
    
    
    from Score s1, Score s2
    
     
    
    
    
    
    
     
    
    
    
     8
    
     
    
    
    
    where s1.sid = s2.sid
    
     
    
    
    
    
    
     
    
    
    
     9
    
     
    
    
    
    and s1.score = s2.score
    
     
    
    
    
    
    
     
    
    
    
    10
    
     
    
    
    
    and s1.cid != s2.cid
    

SQL笔试50题(下)

sql50_41

  • 42.查询每门功课成绩最好的前两名

     1
    
     
    
    
    
    -- 同第二十二题和第二十五题
    
     
    
    
    
    
    
     
    
    
    
     2
    
     
    
    
    
    --
    
     
    
    
    
    
    
     
    
    
    
     3
    
     
    
    
    
    -- row_number() over(partition by 分组字段 order by 排序字段 排序方式) as 别名
    
     
    
    
    
    
    
     
    
    
    
     4
    
     
    
    
    
    select * 
    
     
    
    
    
    from (
    
     
    
    
    
    
    
     
    
    
    
     5
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
     6  sc.sid,
    
     
    
    
    
    
    
     
    
    
    
     7  s.sname,
    
     
    
    
    
    
    
     
    
    
    
     8  s.ssex,
    
     
    
    
    
    
    
     
    
    
    
     9  s.sage,
    
     
    
    
    
    
    
     
    
    
    
    10  c.cname,
    
     
    
    
    
    
    
     
    
    
    
    11  sc.score,
    
     
    
    
    
    
    
     
    
    
    
    12  ROW_NUMBER() 
    
     
    
    
    
    over(
    
     
    
    
    
    partition 
    
     
    
    
    
    BY sc.cid 
    
     
    
    
    
    order 
    
     
    
    
    
    by score 
    
     
    
    
    
    desc) 
    
     
    
    
    
    as myrank
    
     
    
    
    
    
    
     
    
    
    
    13
    
     
    
    
    
    from Score sc,Student s,Course c
    
     
    
    
    
    
    
     
    
    
    
    14
    
     
    
    
    
    where sc.sid = s.sid
    
     
    
    
    
    
    
     
    
    
    
    15
    
     
    
    
    
    and sc.cid = c.cid) t
    
     
    
    
    
    
    
     
    
    
    
    16
    
     
    
    
    
    where t.myrank <
    
     
    
    
    
    3
    

SQL笔试50题(下)

sql50_42

  • 43.统计每门课程的学生选修人数(超过5人的课程才统计)。要求输出课程号和选修人数,查询结果按人数降序排列,若人数相同,按课程号升序排列

    1
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
    2  cid,
    
     
    
    
    
    
    
     
    
    
    
    3  
    
     
    
    
    
    count(
    
     
    
    
    
    sid) 
    
     
    
    
    
    as 
    
     
    
    
    
    '选修人数'
    
     
    
    
    
    
    
     
    
    
    
    4
    
     
    
    
    
    from Score
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    group 
    
     
    
    
    
    by  cid
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    having 
    
     
    
    
    
    count(
    
     
    
    
    
    sid) > 
    
     
    
    
    
    5
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    order 
    
     
    
    
    
    by 
    
     
    
    
    
    count(
    
     
    
    
    
    sid) 
    
     
    
    
    
    desc, cid 
    
     
    
    
    
    asc
    

SQL笔试50题(下)

sql50_43

  • 44.检索至少选修两门课程的学生学号

    1
    
     
    
    
    
    select
    
     
    
    
    
    
    
     
    
    
    
    2  
    
     
    
    
    
    sid,
    
     
    
    
    
    
    
     
    
    
    
    3  
    
     
    
    
    
    count(cid) 
    
     
    
    
    
    as 
    
     
    
    
    
    '选修课程数'
    
     
    
    
    
    
    
     
    
    
    
    4
    
     
    
    
    
    from Score
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    group 
    
     
    
    
    
    by 
    
     
    
    
    
    sid
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    having 
    
     
    
    
    
    count(cid) >= 
    
     
    
    
    
    2
    

SQL笔试50题(下)

sql50_44

  • 45.查询选修了全部课程的学生信息

    1
    
     
    
    
    
    -- 同第十题(条件相反)
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    SELECT a.sid,a.sname,
    
     
    
    
    
    
    
     
    
    
    
    3
    
     
    
    
    
    count(b.cid) 
    
     
    
    
    
    as 
    
     
    
    
    
    '选课数'
    
     
    
    
    
    
    
     
    
    
    
    4
    
     
    
    
    
    FROM Student a
    
     
    
    
    
    
    
     
    
    
    
    5
    
     
    
    
    
    left 
    
     
    
    
    
    join Score b
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    on a.sid = b.sid
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    group 
    
     
    
    
    
    by a.sid,a.sname
    
     
    
    
    
    
    
     
    
    
    
    8
    
     
    
    
    
    having 
    
     
    
    
    
    count(b.cid) = (
    
     
    
    
    
    select 
    
     
    
    
    
    count(
    
     
    
    
    
    distinct cid) 
    
     
    
    
    
    from Course)
    
     
    
    
    
    
    
     
    
    
    
    9
    
     
    
    
    
    order 
    
     
    
    
    
    by a.sid
    

SQL笔试50题(下)

sql50_45

  • 46.查询各学生的年龄

    1
    
     
    
    
    
    -- 利用SYSDATETIME()/getdate() 获取当前时间
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    SELECT SYSDATETIME();
    
     
    
    
    
    
    
     
    
    
    
    3
    
     
    
    
    
    SELECT 
    
     
    
    
    
    
    
     
    
    
    
    4    
    
     
    
    
    
    sid, 
    
     
    
    
    
    
    
     
    
    
    
    5    sname,
    
     
    
    
    
    
    
     
    
    
    
    6    
    
     
    
    
    
    year(SYSDATETIME()) - 
    
     
    
    
    
    year(sage) 
    
     
    
    
    
    AS 
    
     
    
    
    
    '年龄'
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    FROM Student
    

SQL笔试50题(下)

sql50_46

  • 47.查询本周过生日的学生

    1
    
     
    
    
    
    select 
    
     
    
    
    
    getdate();
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    select 
    
     
    
    
    
    DATEADD(wk, 
    
     
    
    
    
    DATEDIFF(wk,
    
     
    
    
    
    0,
    
     
    
    
    
    getdate()), 
    
     
    
    
    
    0);  
    
     
    
    
    
    -- 本周周一
    
     
    
    
    
    
    
     
    
    
    
    3
    
     
    
    
    
    select 
    
     
    
    
    
    DATEADD(wk, 
    
     
    
    
    
    DATEDIFF(wk,
    
     
    
    
    
    0,
    
     
    
    
    
    getdate()), 
    
     
    
    
    
    7) ; 
    
     
    
    
    
    -- 下周周一
    
     
    
    
    
    
    
     
    
    
    
    4
    
     
    
    
    
    SELECT 
    
     
    
    
    
    
    
     
    
    
    
    5  *
    
     
    
    
    
    
    
     
    
    
    
    6
    
     
    
    
    
    FROM Student 
    
     
    
    
    
    
    
     
    
    
    
    7
    
     
    
    
    
    where 
    
     
    
    
    
    DATEADD(
    
     
    
    
    
    year, 
    
     
    
    
    
    year(
    
     
    
    
    
    getdate())-
    
     
    
    
    
    year(sage), sage) 
    
     
    
    
    
    between
    
     
    
    
    
    
    
     
    
    
    
    8
    
     
    
    
    
    DATEADD(wk, 
    
     
    
    
    
    DATEDIFF(wk,
    
     
    
    
    
    0,
    
     
    
    
    
    getdate()), 
    
     
    
    
    
    0) 
    
     
    
    
    
    
    
     
    
    
    
    9
    
     
    
    
    
    and 
    
     
    
    
    
    DATEADD(wk, 
    
     
    
    
    
    DATEDIFF(wk,
    
     
    
    
    
    0,
    
     
    
    
    
    getdate()), 
    
     
    
    
    
    7)
    

 

SQL笔试50题(下)

sql50_47

  • 48.查询下周过生日的学生

     1
    
     
    
    
    
    -- 同第四十七题
    
     
    
    
    
    
    
     
    
    
    
     2
    
     
    
    
    
    select 
    
     
    
    
    
    getdate();
    
     
    
    
    
    
    
     
    
    
    
     3
    
     
    
    
    
    select 
    
     
    
    
    
    DATEADD(wk, 
    
     
    
    
    
    DATEDIFF(wk,
    
     
    
    
    
    0,
    
     
    
    
    
    getdate()), 
    
     
    
    
    
    0);  
    
     
    
    
    
    -- 本周周一
    
     
    
    
    
    
    
     
    
    
    
     4
    
     
    
    
    
    select 
    
     
    
    
    
    DATEADD(wk, 
    
     
    
    
    
    DATEDIFF(wk,
    
     
    
    
    
    0,
    
     
    
    
    
    getdate()), 
    
     
    
    
    
    7) ; 
    
     
    
    
    
    -- 下周周一
    
     
    
    
    
    
    
     
    
    
    
     5
    
     
    
    
    
    SELECT 
    
     
    
    
    
    
    
     
    
    
    
     6  *
    
     
    
    
    
    
    
     
    
    
    
     7
    
     
    
    
    
    FROM Student 
    
     
    
    
    
    
    
     
    
    
    
     8
    
     
    
    
    
    where 
    
     
    
    
    
    DATEADD(
    
     
    
    
    
    year, 
    
     
    
    
    
    year(
    
     
    
    
    
    getdate())-
    
     
    
    
    
    year(sage), sage) 
    
     
    
    
    
    between
    
     
    
    
    
    
    
     
    
    
    
     9
    
     
    
    
    
    DATEADD(wk, 
    
     
    
    
    
    DATEDIFF(wk,
    
     
    
    
    
    0,
    
     
    
    
    
    getdate()), 
    
     
    
    
    
    7) 
    
     
    
    
    
    
    
     
    
    
    
    10
    
     
    
    
    
    and 
    
     
    
    
    
    DATEADD(wk, 
    
     
    
    
    
    DATEDIFF(wk,
    
     
    
    
    
    0,
    
     
    
    
    
    getdate()), 
    
     
    
    
    
    14) 
    
     
    
  • 49.查询本月过生日的学生

    1
    
     
    
    
    
    -- 利用getdate() 获取当前时间, month()获得月份
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    SELECT 
    
     
    
    
    
    getdate();
    
     
    
    
    
    
    
     
    
    
    
    3
    
     
    
    
    
    select 
    
     
    
    
    
    
    
     
    
    
    
    4  
    
     
    
    
    
    sid,
    
     
    
    
    
    
    
     
    
    
    
    5  sname,
    
     
    
    
    
    
    
     
    
    
    
    6  sage,
    
     
    
    
    
    
    
     
    
    
    
    7  ssex
    
     
    
    
    
    
    
     
    
    
    
    8
    
     
    
    
    
    from Student 
    
     
    
    
    
    
    
     
    
    
    
    9
    
     
    
    
    
    where 
    
     
    
    
    
    month(sage) = 
    
     
    
    
    
    month(
    
     
    
    
    
    getdate())
    

SQL笔试50题(下)

sql50_49

  • 50.查询下月过生日的学生

    1
    
     
    
    
    
    -- 同第四十九题
    
     
    
    
    
    
    
     
    
    
    
    2
    
     
    
    
    
    SELECT 
    
     
    
    
    
    getdate();
    
     
    
    
    
    
    
     
    
    
    
    3
    
     
    
    
    
    select 
    
     
    
    
    
    
    
     
    
    
    
    4  
    
     
    
    
    
    sid,
    
     
    
    
    
    
    
     
    
    
    
    5  sname,
    
     
    
    
    
    
    
     
    
    
    
    6  sage,
    
     
    
    
    
    
    
     
    
    
    
    7  ssex
    
     
    
    
    
    
    
     
    
    
    
    8
    
     
    
    
    
    from Student 
    
     
    
    
    
    
    
     
    
    
    
    9
    
     
    
    
    
    where 
    
     
    
    
    
    month(sage) = 
    
     
    
    
    
    month(
    
     
    
    
    
    getdate())+
    
     
    
    
    
    1
    

本文项目地址:

https://github.com/firewang/sql50

(喜欢的话,Star一下)

阅读原文,或者访问该链接可以在线观看(该系列将更新至GitHub,并且托管到read the docs)

https://sql50.readthedocs.io/zh\_CN/latest/

参考网址:

PS:

1. 后台回复“线性代数”,“SQL” 等任一关键词获取资源链接

2. 后台回复“联系“, “投稿“, “加入“ 等任一关键词联系我们

3. 后台回复 “红包” 领取红包

SQL笔试50题(下)

零维领域,由内而外深入机器学习

dive into machine learning

微信号:零维领域

英文ID:lingweilingyu

SQL笔试50题(下)

本文分享自微信公众号 - 零维领域(lingweilingyu)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

点赞
收藏
评论区
推荐文章
Wesley13 Wesley13
2年前
SQL高级查询方法
正文共:5024字2图  预计阅读时间:14分钟前文推送1.SQLServer入门(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU5MTgxNTQyNA%3D%3D%26mid%3D2247
Wesley13 Wesley13
2年前
SQL优化小讲堂汇总
点击上方SQL数据库开发,关注获取SQL视频教程SQL专栏SQL基础知识汇总(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzA3MTg4NjY4Mw%3D%3D%26mid%3D2457298998%26
Wesley13 Wesley13
2年前
SQL优化小讲堂(一)——不查询多余的列和行
想看海景大图的推文吗?将我们设为星标★即可~SQL专栏SQL基础知识汇总(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzA3MTg4NjY4Mw%3D%3D%26mid%3D2457298998%
Stella981 Stella981
2年前
Kaggle最受欢迎的10个竞赛数据集下载
点击上方蓝色字体关注公众号这周两篇文章:1机器学习是万能的吗?AI落地有哪些先决条件?(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzI3NTkyMjA4NA%3D%3D%26mid%3D224748
Stella981 Stella981
2年前
Spring Cloud Alibaba 发布毕业后的首个版本
相信大家对上周的《来自SpringCloud官方的消息,SpringCloudAlibaba即将毕业》(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU4NzU0MDIzOQ%3D%3D%26mid%3D22
Wesley13 Wesley13
2年前
LEAD函数在数据分析中的应用
点击上方SQL数据库开发,关注获取SQL视频教程SQL专栏SQL数据库基础知识汇总(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzA3MTg4NjY4Mw%3D%3D%26mid%3D2457300844
Easter79 Easter79
2年前
ThreadLocal在链路性能测试中实践
在前面的时间,我分享两篇关于ThreadLocal类的文章:利用ThreadLocal解决线程同步问题(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU4MTE2NDEyMQ%3D%3D%26mid%3D224748
Stella981 Stella981
2年前
GitHub iOS 和 Android 正式发布!
推荐阅读:GitHubformobile来了,码农苦逼了!(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzI3ODcxMzQzMw%3D%3D%26mid%3D2247491574%26idx%3D1%26sn%3D
Wesley13 Wesley13
2年前
JDK源码分析
概述前文「JDK源码分析PriorityQueue(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU4NzYyMDE4MQ%3D%3D%26mid%3D2247483966%26idx%3D1%26sn%3D
Easter79 Easter79
2年前
Transact
正文共:2136字5图  预计阅读时间:6分钟前文推送1.SQLServer入门(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU5MTgxNTQyNA%3D%3D%26mid%3D224748465