• sql server 某一列求和


    sql server 某一列求和

    SELECT 患者来源,设备类型,检查部位,设备名称,convert(char(10),STUDY_DATE,121)  as 日期, count(distinct 就诊人次) as 就诊人次--SUM(就诊人数) AS 就诊人数
    			FROM dbo.[V_SeePeople]	WHERE 
    					STUDY_DATE >= '2019-12-04 00:00:00.000' and STUDY_DATE <= '2019-12-11 23:59:59.000'  
    					and OFDEPARTMENT ='FSK'  and ORGNIZATIONCODE ='0101' 
    				GROUP BY 患者来源,设备类型,检查部位,设备名称,convert(char(10),STUDY_DATE,121) --order by convert(char(10),STUDY_DATE,121)
    UNION all
    select '' ,'' ,'' ,'','合计' ,sum( convert(int,temp.就诊人次))AS 就诊人次  from 
     (
     SELECT top 100 percent  患者来源,设备类型,检查部位,设备名称,convert(char(10),STUDY_DATE,121)  as 日期, count(distinct 就诊人次) as 就诊人次--SUM(就诊人数) AS 就诊人数
    			FROM dbo.[V_SeePeople]   	WHERE 
    					STUDY_DATE >= '2019-12-04 00:00:00.000' and STUDY_DATE <= '2019-12-11 23:59:59.000'  
    					and OFDEPARTMENT ='FSK'  and ORGNIZATIONCODE ='0101' 
    				GROUP BY 患者来源,设备类型,检查部位,设备名称,convert(char(10),STUDY_DATE,121) --order by convert(char(10),STUDY_DATE,121) 
    			) as temp  
    

      

    SELECT 患者来源,设备类型,检查部位,设备名称,convert(char(10),STUDY_DATE,121)  as 日期, count(distinct 就诊人次) as 就诊人次--SUM(就诊人数) AS 就诊人数
    			FROM dbo.[V_SeePeople]	WHERE 
    					STUDY_DATE >= '2019-12-04 00:00:00.000' and STUDY_DATE <= '2019-12-11 23:59:59.000'  
    					and OFDEPARTMENT ='FSK'  and ORGNIZATIONCODE ='0101' 
    				GROUP BY 患者来源,设备类型,检查部位,设备名称,convert(char(10),STUDY_DATE,121) --order by convert(char(10),STUDY_DATE,121)
    UNION all
    select '' as 患者来源,'' as 设备类型,'' as 检查部位,''as 设备名称,'合计' as 日期,sum( convert(int,temp.就诊人次))AS 就诊人次  from 
     (
     SELECT top 100 percent  患者来源,设备类型,检查部位,设备名称,convert(char(10),STUDY_DATE,121)  as 日期, count(distinct 就诊人次) as 就诊人次--SUM(就诊人数) AS 就诊人数
    			FROM dbo.[V_SeePeople]   	WHERE 
    					STUDY_DATE >= '2019-12-04 00:00:00.000' and STUDY_DATE <= '2019-12-11 23:59:59.000'  
    					and OFDEPARTMENT ='FSK'  and ORGNIZATIONCODE ='0101' 
    				GROUP BY 患者来源,设备类型,检查部位,设备名称,convert(char(10),STUDY_DATE,121) --order by convert(char(10),STUDY_DATE,121) 
    			) as temp   
    

    注意:sql 存储 中 select ''  == select '''' 

    eg:

    set @sqlstr2 = ' UNION all select '''' ,'''' ,'''' ,'''' ,''合计'',sum( convert(int,temp.就诊人数))AS 就诊人数
    from (SELECT top 100 percent '+@SelectName+@sdate+' as 日期,
    count(distinct 就诊人数) as 就诊人数 FROM dbo.[V_SeePeople] WHERE
    '+@sDateColum+' >= '''+ @sStartDate+' 00:00:00' +''' and '+@sDateColum+' <= ''' +@sEndDate+' 23:59:59'+''' '+@sMod+'
    GROUP BY '+@GroupName + @sdate + ') as temp' ;

      

  • 相关阅读:
    jquery+ajax+ashx。ashx的使用方法
    如何在ashx页面获取Session值
    模式DIV。
    .net 中文传参
    5分钟无操作,退出,操作方法,关闭页面
    SQL Server DATEDIFF() 函数(SQL计算时间差)
    Sql server 事务的两种用法
    正则表达式相关
    jQuery AJAX实现调用页面后台方法。调用ashx方法
    时间差(类.精确到秒).net中实现Datediff类C#
  • 原文地址:https://www.cnblogs.com/YYkun/p/12027390.html
Copyright © 2020-2023  润新知