zoukankan      html  css  js  c++  java
  • 分上下半月统计 SQL

    代码
    declare   @t   table   (Date   datetime,   Name   varchar(30),   Money   money)   
      
    insert   @t   
      
    select   dateadd(dd,10,getdate()),'a',10.0000   union   all   
      
    select   dateadd(dd,11,getdate()),'a',10.0000   union   all   
      
    select   dateadd(dd,12,getdate()),'b',10.0000   union   all   
      
    select   dateadd(dd,13,getdate()),'b',10.0000   union   all   
      
    select   dateadd(dd,6,getdate()),'b',10.0000   union   all   
      
    select   dateadd(dd,-1,getdate()),'a',10.0000   union   all   
      
    select   dateadd(dd,-2,getdate()),'a',10.0000   union   all   
      
    select   dateadd(dd,-3,getdate()),'b',10.0000   union   all   
      
    select   dateadd(dd,-4,getdate()),'b',10.0000   union   all   
      
    select   dateadd(dd,-40,getdate()),'b',10.0000   union   all   
      
    select   dateadd(dd,-20,getdate()),'b',10.0000   union   all   
      
    select   dateadd(dd,30,getdate()),'b',10.0000   union   all   
      
    select   dateadd(dd,60,getdate()),'b',10.0000   
      
    SELECT   CONVERT(VARCHAR(7),Date,120)+'-'+   
      
    case   when   day(date)   between   1   and   15   then   '上半月'   else   '下半月'   end,   
      Name,   
      
    SUM(Money)     
      
    FROM   @t   t   
      
    GROUP   BY   CONVERT(VARCHAR(7),Date,120)+'-'+   
      
    case   when   day(date)   between   1   and   15   then   '上半月'   else   '下半月'   end,   
      Name

    欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/

  • 相关阅读:
    任务信息的高级选项(Project)
    延时间隔(Project)
    在【自定义列】中使用M函数(Power Query 之 M 语言)
    在对话框中设置前置任务(Project)
    前置任务(Project)
    拖动条形图设置任务关联(Project)
    2020最新移动,联通,电信号码正则
    2019最新移动,联通,电信号码正则
    原生js判断手机端页面滚动停止
    win10下vue-devtools的安装和使用
  • 原文地址:https://www.cnblogs.com/Tonyyang/p/1732231.html
Copyright © 2011-2022 走看看