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

时间:2021-08-13 19:15:07
关键字:FULL JOIN
只要其中某个表存在匹配,FULL JOIN 关键字就会返回行。
 select a.createtime, ISNULL(lp, 0) lp , ISNULL(hp, 0) hp
from (
select convert(nvarchar(10),cCreateTime,23) as createtime,count(iTotalAmount) as lp
from vat_inv_standard
where iCharacter = 0 and iStatus = 0 and DateDiff(dd,cCreateTime,getdate())<=7
group by convert(nvarchar(10),cCreateTime,23)
) A FULL JOIN (
select convert(nvarchar(10),cCreateTime,23) as createtime,count(iTotalAmount) as hp
from vat_inv_standard
where iCharacter = 1 and iStatus = 0 and DateDiff(dd,cCreateTime,getdate())<=7
group by convert(nvarchar(10),cCreateTime,23)
) B on a.createtime = b.createtime
---------------------
作者:卡尔小布丁
来源:CSDN
原文:https://blog.csdn.net/ljh1993531/article/details/80077594 详细教程:http://www.w3school.com.cn/sql/sql_join_full.asp