首页 > 代码库 > 用sql语句按周、按月、按季、按年统
用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 employeewhere year(createDate) >= ‘2006‘ group byweek(createDate),month(createDate),quarter(createDate),year(createDate) --sqlserver2005语法统计按周,月,季,年。--按日--select sum(price),day([date]) from table_name where year([date]) =‘2006‘ group by day([date])--按周quarterselect sum(price),datename(week,price_time) from ble_name whereyear(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 whereyear(price_time) = ‘2008‘ group by datename(quarter,price_time)--按年select sum(price),year(price_time) from ble_name whereyear(price_time) >= ‘2008‘ group by year(price_time)
用sql语句按周、按月、按季、按年统
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。