您好,欢迎来到微智科技网。
搜索
您的当前位置:首页sql时间分组

sql时间分组

来源:微智科技网
sql时间分组

select Convert(varchar(7),YearMonth,23)as A , SUM(

CASE WHEN Minor = '1' THEN - Convert(int,Number1) WHEN Minor = '3' and [Audit] = 2 THEN - Convert(int,Number1) WHEN Minor = '2' THEN Convert(int,Number1) WHEN Minor = '4' THEN Convert(int,Number1) END )

from T_User_Commodity

group by Convert(varchar(7),YearMonth,23)

select Convert(varchar(7),PetitionTime,23)as A1,count(*) C1 from Petition group by Convert(varchar(7),PetitionTime,23)

select Convert(varchar(7),MediationTime,23)as A2,count(*) C2 from Mediation group by Convert(varchar(7),MediationTime,23)

--先 A表时间和B表时间 列合并; 之后 在joinselect A.⽉份, B.C1,C.C2 from (

select distinct Convert(varchar(7),PetitionTime,23) as ⽉份 from Petition union select distinct Convert(varchar(7),MediationTime,23) as ⽉份 from Mediation ) A

left join (select Convert(varchar(7),PetitionTime,23)as A1,count(*) C1 from Petition group by Convert(varchar(7),PetitionTime,23)) B on A.⽉份=B.A1left join (

select Convert(varchar(7),MediationTime,23)as A2,count(*) C2 from Mediation group by Convert(varchar(7),MediationTime,23)) C on A.⽉份=C.A2--- 查询不全; 若B表中在A表中没有出现(时间列); 则统计不全 select * from(

select Convert(varchar(7),PetitionTime,23)as A1,count(*) C1 from Petition group by Convert(varchar(7),PetitionTime,23) )A

left join(

select Convert(varchar(7),MediationTime,23)as A2,count(*) C2 from Mediation group by Convert(varchar(7),MediationTime,23) )B on

A.A1 = B.A2

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务