zoukankan      html  css  js  c++  java
  • - 查询“生物”课程比“物理”课程成绩高的所有学生的学号;

    -- 查询“生物”课程比“物理”课程成绩高的所有学生的学号;
    
    -- 方法一
    
    select * from score a LEFT JOIN course b on a.course_id = b.cid where b.cname='生物'   
    
    
    select * from score a LEFT JOIN course b on a.course_id = b.cid where b.cname='物理'   
    
    
    SELECT c.student_id,c.num,d.num from (select a.student_id,a.num,b.cname from score a LEFT JOIN course b on a.course_id = b.cid where b.cname='生物')as c  LEFT JOIN
    (select * from score a LEFT JOIN course b on a.course_id = b.cid where b.cname='物理' )  d on c.student_id = d.student_id  WHERE c.num > IFNULL(d.num,0)
    
    
    -- 方法2--
     select  a.student_id,MAX(case b.cname when '生物' THEN a.num ELSE 0 end)  '生物' ,MAX(case b.cname when '物理' THEN a.num ELSE 0 end)  '物理' 
    from score a LEFT JOIN course b on a.course_id = b.cid GROUP BY a.student_id HAVING 生物 > 物理 -- 方法3 select a.student_id, (select num from score h LEFT JOIN course m on h.course_id = m.cid where m.cname='生物' and h.student_id=a.student_id ) as shengwu,
    (select num from score h LEFT JOIN course m on h.course_id = m.cid where m.cname='物理' and h.student_id=a.student_id ) as wuli from score a GROUP BY a.student_id
  • 相关阅读:
    BZOJ3036: 绿豆蛙的归宿
    BZOJ1419: Red is good
    BZOJ1013: [JSOI2008]球形空间产生器sphere
    BZOJ1415: [Noi2005]聪聪和可可
    BZOJ1417: Pku3156 Interconnect
    BZOJ1076: [SCOI2008]奖励关
    BZOJ2318: Spoj4060 game with probability Problem
    BZOJ1426: 收集邮票
    BZOJ2720: [Violet 5]列队春游
    BZOJ2698染色
  • 原文地址:https://www.cnblogs.com/zjchao/p/9125937.html
Copyright © 2011-2022 走看看