zoukankan      html  css  js  c++  java
  • left join 左边有数据,右边无数据

     
    主要是andwhere的区别:
     
    原Sql:
    select a.ID as reqid,(select top 1 Convert(nvarchar(50),jhdatez,111) from CS_OrderPro
    where Codeno=a.InvNo and iProductId =a.iProductId)as 'jhdate',
    (select top 1 Deptname from UserInfo left join Department on  UserInfo.deptid=Department.Deptid where UserInfo.userid=AuditUserId) as deptname,
    (select isnull(SUM(iNum),0) from CS_OrderPro where CS_OrderPro.zid=a.ID and  CS_OrderPro.codeno=a.Invno) as cgnum,
    (select top 1 InvNO from CS_OrderPro where CS_OrderPro.zid=a.ID and  CS_OrderPro.codeno=a.Invno) as cginvno,
    (select isnull(SUM(CS_InvRecBill.iNum),0) from CS_InvRecBill
    left join  CS_OrderPro on CS_InvRecBill.zid=CS_OrderPro.ID
    where CS_OrderPro.zid=a.ID and CS_OrderPro.codeno=a.Invno) as rknum,*,
    isnull((select sum(pronum) from cs_stock where proid=a.iproductid),0) as kcnum,
    comoditiestype from CS_OrderRequise a left join CS_OrderRequiseList c on c.OutCode=a.InvNO
    left join B_Products b on b.id=a.iProductID 
    left join ComoditiesType on ComoditiesType.typeid=b.typeid    where 1=1 and c.isend=1 and  ComoditiesType.typeid<>336

    左连接查询后,最后的where语句过滤了本该显示的数据。

    修改过的Sql:

    select a.ID as reqid,(select top 1 Convert(nvarchar(50),jhdatez,111) from CS_OrderPro
    where Codeno=a.InvNo and iProductId =a.iProductId)as 'jhdate',
    (select top 1 Deptname from UserInfo left join Department on  UserInfo.deptid=Department.Deptid where UserInfo.userid=AuditUserId) as deptname,
    (select isnull(SUM(iNum),0) from CS_OrderPro where CS_OrderPro.zid=a.ID and  CS_OrderPro.codeno=a.Invno) as cgnum,
    (select top 1 InvNO from CS_OrderPro where CS_OrderPro.zid=a.ID and  CS_OrderPro.codeno=a.Invno) as cginvno,
    (select isnull(SUM(CS_InvRecBill.iNum),0) from CS_InvRecBill
    left join  CS_OrderPro on CS_InvRecBill.zid=CS_OrderPro.ID
    where CS_OrderPro.zid=a.ID and CS_OrderPro.codeno=a.Invno) as rknum,*,
    isnull((select sum(pronum) from cs_stock where proid=a.iproductid),0) as kcnum,
    comoditiestype from CS_OrderRequise a left join CS_OrderRequiseList c on c.OutCode=a.InvNO
    left join B_Products b on b.id=a.iProductID
    left join ComoditiesType on ComoditiesType.typeid=b.typeid AND   ComoditiesType.typeid<>336   where 1=1 and c.isend=1 
  • 相关阅读:
    kafka注册异常
    Android基于XMPP Smack Openfire下学习开发IM(五)连接断开重连
    openfire维持在线状态,监听消息
    openfire ping的smack解决方案(维持在线状态)
    openfire聊天记录插件
    openfire 发送 接受 注册 广播 好友列表 在线状态
    maven仓库中心mirrors配置多个下载中心(执行最快的镜像)
    开发openfire 消息拦截器插件PacketInterceptor
    Openfire注册流程代码分析
    linux centOS6 nexus 开启自动启动
  • 原文地址:https://www.cnblogs.com/ywkcode/p/11491757.html
Copyright © 2011-2022 走看看