• 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' ;

      

  • 相关阅读:
    canvas的基本用法
    h5新增属性
    jquery中遍历
    git版本控制器
    bootstrap-datetimepicker时间插件
    layer.load的使用
    ajax请求json中的数据
    h5中input的request属性提示文字字段
    layUI
    v-show v-if 的使用
  • 原文地址:https://www.cnblogs.com/YYkun/p/12027390.html
Copyright © 2020-2023  润新知