宜春二期

SELECT rpad(substr(a.ZGSWSKFJ_DM,1,7),11,'0') xjdm,COUNT(DISTINCT A.DJXH) QSHS                                                                                                                              
  FROM HX_ZS.ZS_YJSF A, HX_DJ.DJ_NSRXX B
 WHERE A.DJXH = B.DJXH(+)
   AND YBTSE <> 0
   AND SKCLLX_DM <> '6' 
   AND (YZCLRQ IS NULL OR YZCLRQ >= (DATE '2017-07-31' + 1))
   AND YZFSRQ < (DATE '2017-07-31' + 1) 
GROUP BY rpad(substr(a.ZGSWSKFJ_DM,1,7),11,'0')

这里是计算a.djxh不为空的数量,下面列出明细的时候就只能出现a.djxh,不能出现a.ZGSWSKFJ_DM,因为左连接会将a表的所有数据列出来,即使不满足A.DJXH =B.DJXH的数据也会列出来,如果查询中出现a.ZGSWSKFJ_DM,那么即使a.djxh不存在的数据也会列出来,这样就会多查询出数据。

 

SELECT distinct
b.ZGSWSKFJ_DM,b.ZGSWJ_DM,b.SSGLY_DM,b.NSRSBH,b.NSRMC,         只能是b.ZGSWSKFJ_DM不能是a.ZGSWSKFJ_DM           
a.DJXH
  FROM HX_ZS.ZS_YJSF A, HX_DJ.DJ_NSRXX B
 WHERE A.DJXH = B.DJXH(+)
   AND YBTSE <> 0
   AND SKCLLX_DM <> '6' 
   AND (YZCLRQ IS NULL OR YZCLRQ >= (DATE '2017-07-31' + 1))
   AND YZFSRQ < (DATE '2017-07-31' + 1)
   and rpad(substr(a.ZGSWSKFJ_DM,1,7),11,'0') = '13609230000'

posted @ 2018-04-14 14:30  神只吃苹果  阅读(167)  评论(0编辑  收藏  举报