1. --1.查询语文成绩前两名的学生名称
    2. select top(2) * from grade where subject = '语文' order by score desc;
    3. --2.查询语文大于60的学生名称
    4. select * from grade g,student s where g.s_id = s.id and g.subject = '语文' and g.score > 60;
    5. --3.查询学生id1的学生的分数平均值 (各个科目总分/科目)
    6. select avg(score) from grade g where g.s_id = 1
    7. --4.查询学生的语文成绩,并按照倒序排名
    8. select * from grade g where subject = '语文' order by score asc;
    9. --5.查询科目70分以上的学生名称还有年龄
    10. -- 1. 查询的表有哪些 grade student
    11. -- 2.确定要查询的字段student.name studen.age
    12. -- 3.确定筛选条件
    13. -- a:grade.score > 70
    14. -- 确定关联关系 学生表.id = 成绩表的.stu_id
    15. select s.name,s.age,g.score from grade g, student s where s.id= g.s_id and g.score > 70
    1. -- 使用子查询
    2. -- in
    3. -- 查询姓名是老子 孟子 孔子
    4. -- student
    5. -- name = 老子 孟子 孔子
    6. select * from student where name = '老子' or name = '孟子' or name = '孔子'
    7. select * from student where name in ('老子','孟子','孔子');
    8. -- exists判断是否存在 然后执行
    9. -- sqla where exists (sqlb)
    10. -- 如果sqlb能查询到数据 就返回true 然后就执行sqla
    11. -- 如果sqlb查询不到数据 就返回flase 就不执行
    12. select * from student where EXISTS (select * from student where id = 1)
    13. --嵌套子查询 当一个查询的条件依赖与另一个查询的结果
    14. -- 查询成绩大于语文60分学生名称
    15. select s_id from grade where score > 60 and subject = '语文';
    16. select * from student where id in(select s_id from grade where score > 60 and subject = '语文')
    17. -- 查询平均分大于分的学生
    18. select avg(score) from grade; -- 查询平均分
    19. select s_id from grade where score >(select avg(score) from grade )-- 查询大于平均分的
    20. select * from student where id in(select s_id from grade where score >(select avg(score) from grade ))
    21. select * from student where id in (2,1,1) -- in查询是带去重的