• mysql查询(四)


    查询存在" A001 "课程但可能不存在" A002 "课程的情况(不存在时显示为 null

    成绩表为:ex_chengjibiao_95

    (1)查询A001

    命令:SELECT * from ex_chengjibiao_95 WHERE CId='A001'

    (2)查询A002

    命令:SELECT * from ex_chengjibiao_95 WHERE CId='A002'

    (3)满足存在A001,但是未必存在

             满足A001方向结果,未必满足A002方向结果

    命令:SELECT a.Sid,a.Cid,a.score,b.Cid,b.score from

    (SELECT * from ex_chengjibiao_95 WHERE Cid='A002')as a

    left join

    (SELECT * from ex_chengjibiao_95 WHERE CId='A001')as b

    ON a.Sid=b.Sid

    (4)对比,满足A002,未必满足A001方向结果

    命令:SELECT a.Sid,a.Cid,a.score,b.Cid,b.score from

    (SELECT * from ex_chengjibiao_95 WHERE Cid='A002')as a

    right join

    (SELECT * from ex_chengjibiao_95 WHERE CId='A001')as b

    ON a.Sid=b.Sid

    left join(左连接) ,满足左边条件,右边可能为空

    right join(右连接),满足右边条件,左边可能为空

  • 相关阅读:
    C#Redis分布式缓存
    CPU核心数
    关于RSA加密
    C#.NET中的CTS、CLS和CLR
    silverlight依赖属性
    silverlight imagesource赋值与转换
    #我的java之多态和接口#
    #什么是 spring boot#
    #替换eclipse自带的maven#
    #从零开始的maven异世界#
  • 原文地址:https://www.cnblogs.com/zgqbky/p/13425494.html
Copyright © 2020-2023  润新知