要有一个客户表,列出所有客户,下面假定它的名称是c,另外cust中的FK是customname:
select c.customname,isnull(sum(cust.total),0)
from c left join cust on cust.customname = c.customname
where year(cust.notedate)='2005'
group by c.customname
如果没有客户表,客户名称再cust里面:
select a.customname,isnull(sum(cust.total),0)
from (select dictinct customname from cust) a left join cust on cust.customname=a.customname
where year(cust.notedate)='2005'
group by a.customname
要有一个客户表,列出所有客户,下面假定它的名称是c,另外cust中的FK是customname:
select c.customname,isnull(sum(cust.total),0)
from c left join cust on cust.customname = c.customname
where year(cust.notedate)='2005'
group by c.customname
如果没有客户表,客户名称再cust里面:
select a.customname,isnull(sum(cust.total),0)
from (select dictinct customname from cust) a left join cust on cust.customname=a.customname
where year(cust.notedate)='2005'
group by a.customname