zoukankan      html  css  js  c++  java
  • 找出所有课程高于80分的学生

    有2个表   学生表(Student)  成绩表(grade)

     

    一、方法1 反向求解

    可以从反面求解,只要有一门课程不满足条件,则该学生不再考虑   select distinct g.no from grade g where g.socre<80

    然后在学生表中反向求解学生 ,条件为学号不在上面查询的集合中的  

    select t.name,t.no from student t where t.no not in (
    select distinct g.no from grade g where g.socre<80)  

     二、方法2  使用having min()与group by 

    select m.name from (  select t.name, t.no, g.class_no, g.socre

    from student t
      left join grade g
        on g.no = t.no) m
        group by m.name
    having min(m.socre)>= 83

    三、方法3  使用 not exist 


    select *
    from student t
    where t.no not in (select distinct a.no
    from grade a
    where not exists (select 1
    from grade b
    where b.socre < 80
    and b.no = a.no))

    linux下的docker操作命令及异常
  • 相关阅读:
    MySQL创建数据库与创建用户以及授权
    java关于map用来筛选的用法
    C#实体类的关联运用
    PHP 数据库基础操作
    PHP 文件操作
    PHP 加密和解密
    PHP 图形处理
    PHP Cookie和Session
    SQL基本操作
    JAVA基本术语
  • 原文地址:https://www.cnblogs.com/ketoli/p/14891383.html
Copyright © 2011-2022 走看看