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

本文深入解析了FULLJOIN关键字的使用方法,通过具体案例展示了如何在SQL中利用FULLJOIN来处理两个表的数据,确保即使某表不存在匹配项也能返回所有行。特别介绍了在vat_inv_standard表中对不同特性数据进行汇总分析的全过程。
关键字: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 来源:优快云 
16 原文:https://blog.youkuaiyun.com/ljh1993531/article/details/80077594 

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

 

转载于:https://www.cnblogs.com/luojie-/p/10681743.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值