日期:2014-05-16  浏览次数:20817 次

求救!!!超简单的一个统计怎么实现???分就这么多啦。
求救!!!超简单的一个统计怎么实现???分就这么多啦。
表:销售号 时间 金额 员工 数量
SellNo SellTime Money cusName WaterNum 
SH090606-00001 2009-6-16 17:06:28 100 张三 10
SH090606-00002 2009-6-16 17:39:09 50 李四 5
SH090608-00003 2009-6-18 13:17:00 100 三五 10
SH090617-00004 2009-6-17 11:55:45 50 李四 5
SH090918-00005 2009-9-18 20:27:10 100 小刘 10
SH091213-00006 2009-12-13 17:17:35 50 张三 5
SH091213-00007 2009-12-13 17:22:10 50 李四 5
SH091213-00008 2009-12-13 17:24:43 100 张三 10
SH100102-00009 2010-11-12 18:00:32 60 三五 6

1、按cusName统计:
cusName Money WaterNum 
张三 250 25
李四 150 15
三五 160 16
总计 560 56

另外:如果想按年,月,日来统计应该怎么做?



------解决方案--------------------
1、按cusName统计:
cusName Money WaterNum
张三 250 25
李四 150 15
三五 160 16
总计 560 56

SQL code
select cusName,sum(Money),sum(WaterNum)
from 表
group by cusName
union all
select '总计',sum(Money),sum(WaterNum)
from 表

------解决方案--------------------

select selltime,sum(money)
from 表名
group by selltime


select selltime,sum(money)
from 表名
where selltime between 2009-06-1 and 2009-06-31
group by selltime 


select selltime,sum(money)
from 表名
where selltime between 2009-01-1 and 2009-12-31
group by selltime 

www.hzyatong.cn
www.tuoye.net


------解决方案--------------------
1、按年统计:
年份 Money WaterNum
2009 ... ...
2010 560 56
2011 ... ...



SQL code
select year(SellTime) ,cusName,sum(Money),sum(WaterNum)
from 表
group by year(SellTime),cusName

------解决方案--------------------

select year(selltime),sum(Money),sum(WaterNum) from tt group by year(selltime)


select month(selltime),sum(Money),sum(WaterNum) from tt group by month(selltime)