mssql sql 日期函数实例

原创
2016-06-07 17:48:08 859浏览


select 日期,自选字段1,自选字段2,sum(类型1) 类型1,sum(类型2) 类型2,sum(类型3) 类型3,sum(类型4) 类型4,sum(类型5) 类型5,sum(类型6) 类型6 from (
select to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd') 日期,自选字段1,自选字段2,count(主键字段) 类型1,0 类型2,0 类型3,0 类型4,0 类型5,0 类型6 from 表名
where 1=1
group by to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd'),自选字段1,自选字段2
union all
select to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd') 日期,自选字段1,自选字段2,0 类型1,count(主键字段) 类型2,0 类型3,0 类型4,0 类型5,0 类型6 from 表名
where 1=1
group by to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd'),自选字段1,自选字段2
union all
select to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd') 日期,自选字段1,自选字段2,0 类型1,0 类型2,count(主键字段) 类型3,0 类型4,0 类型5,0 类型6 from 表名
where 1=1
group by to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd'),自选字段1,自选字段2
union all
select to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd') 日期,自选字段1,自选字段2,0 类型1,0 类型2,0 类型3,count(主键字段) 类型4,0 类型5,0 类型6 from 表名
where 1=1
group by to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd'),自选字段1,自选字段2
union all
select to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd') 日期,自选字段1,自选字段2,0 类型1,0 类型2,0 类型3,0 类型4,count(主键字段) 类型5,0 类型6 from 表名
where 1=1
group by to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd'),自选字段1,自选字段2
union all
select to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd') 日期,自选字段1,自选字段2,0 类型1,0 类型2,0 类型3,0 类型4,0 类型5,count(主键字段) 类型6 from 表名
where 1=1
group by to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd'),自选字段1,自选字段2 ) where 1=1 group by to_date(to_char(日期,'yyyy-mm-dd'),'yyyy-mm-dd'),自选字段1,自选字段2

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。