zoukankan      html  css  js  c++  java
  • SQL Server按照日、周、月、年统计数据

    表:consume_record
    字段:consume (money类型)
    date (datetime类型)

    四条sql语句分别按日,按周,按月,按季统计消费总量.
    如:1月 1200元
    2月 3400元
    3月 2800元

    -–按日   
    select sum(consume),day([date]) from consume_record where year([date]) = ’2010′ group by day([date])   
    -–按周quarter   
    select sum(consume),datename(week,[date]) from consume_record where year([date]) = ’2010′ group by datename(week,[date])   
    -–按月   
    select sum(consume),month([date]) from consume_record where year([date]) = ’2010′ group by month([date]
    -–按季   
    select sum(consume),datename(quarter,[date]) from consume_record where year([date]) = ’2010′ group by datename(quarter,[date])   
    
    -–指定日期可按上面的例子变通下,无非就是一个聚合函数和Group by  
    select [date],sum(consume) from consume_record where [date] between ’2010-06-01′ and ’2010-07-10′ group by [date]  
    
  • 相关阅读:
    API
    MVC判断是否登录
    MVC收藏店铺
    MVC显示界面
    MVC登录
    MVC登录跳转到显示
    MVC退单
    MVC判断登录
    Oracle 千位符转换,及格式转换
    【转】Java 服务端 和 C# 客户端 实现 Socket 通信
  • 原文地址:https://www.cnblogs.com/robinli/p/1924743.html
Copyright © 2011-2022 走看看