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

Posted 有梦就能实现

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用sql语句按周按月按季按年统计相关的知识,希望对你有一定的参考价值。

--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语句按周按月按季按年统计的主要内容,如果未能解决你的问题,请参考以下文章

MySQL统计函数记录——按月按季度按日时间段统计

oracle表分区详解(按天按月按年等)

按月按日进行数据统计的Mysql语句

如何在mysql中group by week

adobe acrobat xi pro这软件多少钱

Mysql按周,按月,按日,按小时分组统计数据