sql相同表不同查询条件合并显示

关键字:FULL JOIN
只要其中某个表存在匹配,FULL JOIN 关键字就会返回行。
 1 select a.createtime, ISNULL(lp, 0) lp , ISNULL(hp, 0) hp
 2  from (
 3     select  convert(nvarchar(10),cCreateTime,23) as createtime,count(iTotalAmount) as lp
 4     from vat_inv_standard 
 5     where iCharacter = 0 and iStatus = 0 and DateDiff(dd,cCreateTime,getdate())<=7
 6     group by convert(nvarchar(10),cCreateTime,23)
 7 ) A FULL JOIN (
 8     select convert(nvarchar(10),cCreateTime,23) as createtime,count(iTotalAmount) as hp 
 9     from vat_inv_standard 
10     where iCharacter = 1 and iStatus = 0 and DateDiff(dd,cCreateTime,getdate())<=7
11     group by convert(nvarchar(10),cCreateTime,23)
12 ) B on  a.createtime =  b.createtime
13 --------------------- 
14 作者:卡尔小布丁 
15 来源:CSDN 
16 原文:https://blog.csdn.net/ljh1993531/article/details/80077594 

详细教程:http://www.w3school.com.cn/sql/sql_join_full.asp

 

posted @ 2019-04-10 10:27  原来是个帅小伙  阅读(1630)  评论(0编辑  收藏  举报