我有一个代码,将所有的代表新客户和他们的年份销售。唯一的问题是,它只会吸引在invdate范围内销售的客户,但如果他们没有任何销售额,我需要它显示所有的账户为0。有什么办法可以做到这一点?我尝试使用COALESCE,它似乎没有工作。我也尝试使用左,右,全外连接。任何帮助,将不胜感激!如何显示客户,即使他们没有销售(结果)
select
a.Acctnum,
sum(a.invtotal) as total
from invoices a right join accounts b on a.acctnum = b.acctnum where
a.invdate between '1/1/2017' and '12/31/2017'
and a.sls = '78'
and b.sls = '78'
and b.activetype = 'y' and b.startdate > (getdate()-365)
group by a.acctnum
order by total desc
嗯,这似乎是有道理的。但是,把它们放入ON子句中究竟意味着什么? – Vexxums
查看@ JNevill的回答。 – HLGEM