• 全部
• 基础类
• 应用实例
• 新技术前沿

# 请教一个SUM的问题

select sum(total) from cust where year(notedate) = '2005'

...全文
151 点赞 收藏 10

10 条回复

NinGoo 2005-01-07

lxysjl 2005-01-07
select 客户名 from 客户表 as a left join (select 客户名,sum(total) from cust where year(notedate) = '2005' group by 客户名 ) as b on a.客户名=b.客户名

1楼说的不错,要有一个客户表,再用left join

zhuxiaojun2002 2005-01-07

select sum(total) from cust where year(notedate) = '2005'

2005年没有发生销售的为0，你求的是所有客户2005年的销售量。0统计出来加到sum中有什么用啊？

xluzhong 2005-01-07
select distinct 客户 into #t from cust

select #t.*,sum(cust.total)
from #t
left join cust
on #t.客户=cust.客户
where year(notedate) = '2005'

long_205 2005-01-07

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

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

nicebee 2005-01-06

select custname,sum(money) from cust
where year(notedate)='2005'
group by custname

canyqf 2005-01-06

canyqf 2005-01-06

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

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

MS-SQL Server

3.3w+

MS-SQL Server相关内容讨论专区

2005-01-06 11:21