22,207
社区成员
发帖
与我相关
我的任务
分享
create table test(id int ,Account varchar(50),type varchar(50),time datetime)
insert into test(id,Account,Type,[Time])
select 1,'张三',0,'2020-05-22 10:22:33'
union select 2,'李四',20,'2020-05-22 11:22:33'
union select 3,'王二',1,'2020-05-23 10:22:33'
union select 4,'张三',0,'2020-05-24 10:22:33'
union select 5,'张三',2,'2020-05-25 10:42:33'
union select 6,'张三',0,'2020-05-26 10:25:31'
union select 7,'张三',3,'2020-05-26 10:25:33'
union select 8,'张三',10,'2020-05-27 10:25:33'
select * from
(
select CONVERT(varchar(10),time,120) as time,type from test
) a
pivot (count(type) for type in ([0],[1],[2],[3],[4],[11],[20]) ) as t