日期:2014-05-16 浏览次数:20612 次
---1.sql
SELECT * FROM (SELECT RKDH,
CONVERT(varchar(10), UPLOADTIME, 120) AS LOADTIME from dbo.BO_ZHKCSJ AS SJ INNER JOIN BO_CRKMX AS MX ON
SJ.RKDH=MX.CRKDH INNER JOIN BO_CRKTAB AS TAB ON MX.BINDID=TAB.BINDID where
RKDH not in (select CRKDH from BO_ZHKCSJBZY) group by RKDH,UPLOADTIME) AS CCC
group by RKDH,LOADTIME
-----2.sql
SELECT RKDH,COUNT(DJPQ)as no FROM dbo.BO_ZHKCSJ GROUP BY RKDH
----执行结果:
----1
RKDH LOADTIME
CSRK00001 2014-03-18
CSRK00002 2014-03-18
---2
RKDH no
CSRK00001 32
CSRK00002 0
---能将两条语句连接起来吗?在第二种情况下,当RKDH对应的no为0时就不显示。
---想要的结果:
RKDH LOADTIME
CSRK00001 2014-03-18
SELECT * FROM
(
SELECT * FROM (SELECT RKDH,
CONVERT(varchar(10), UPLOADTIME, 120) AS LOADTIME from dbo.BO_ZHKCSJ AS SJ INNER JOIN BO_CRKMX AS MX ON
SJ.RKDH=MX.CRKDH INNER JOIN BO_CRKTAB AS TAB ON MX.BINDID=TAB.BINDID where
RKDH not in (select CRKDH from BO_ZHKCSJBZY) group by RKDH,UPLOADTIME) AS CCC
group by RKDH,LOADTIME) AS a
INNER JOIN
(SELECT RKDH,COUNT(DJPQ)as no FROM dbo.BO_ZHKCSJ GROUP BY RKDH)AS b
ON
a.RKDH=b.RKDH AND b.no<>0