码迷,mamicode.com
首页 > 数据库 > 详细

用sql语句按周、按月、按季、按年统

时间:2014-10-06 22:09:30      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   ar   sp   div   art   c   

原文地址:http://hi.baidu.com/%BD%F0%D3%F1kl_y/blog/item/1c368ffba9388476024f5645.html

--按mySql语法统计按周,月,季,年。income为合计的价格字段,createDate为交易时间。
select sum(income)as revenue,week(createDate) as week,month(createDate) as month,
quarter(createDate)as quarter,year(createDate)as year from employee
where year(createDate) >= 2006 group by
week(createDate),month(createDate),quarter(createDate),year(createDate)
 
--sqlserver2005语法统计按周,月,季,年。
--按日
--select sum(price),day([date]) from table_name where year([date]) =
2006 group by day([date])
--按周quarter
select sum(price),datename(week,price_time) from ble_name where
year(price_time) = 2008 group by datename(week,price_time)
--按月
select sum(price),month(price_time) from ble_name where year(price_time)
= 2008 group by month(price_time)
--按季
select sum(price),datename(quarter,price_time) from ble_name where
year(price_time) = 2008 group by datename(quarter,price_time)
--按年
select sum(price),year(price_time) from ble_name where
year(price_time) >= 2008 group by year(price_time)

 

用sql语句按周、按月、按季、按年统

标签:style   blog   http   color   ar   sp   div   art   c   

原文地址:http://www.cnblogs.com/niaowo/p/4008683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!