sqlserver怎么实现同一个表中多个count查询并且分组并且统计总数
1个回答
展开全部
declare @t table (hm varchar(10),fy int)
insert @t values ('23456',12)
insert @t values ('56423',13)
insert @t values ('56321',15)
insert @t values ('89546',25)
insert @t values ('78965',85)
insert @t values ('56789',88)
select bj,count(fy) as sl,sum(fy) as hj from (
select *,substring(cast(fy as varchar(10)),1,1) as bj
from @t) a
group by bj
insert @t values ('23456',12)
insert @t values ('56423',13)
insert @t values ('56321',15)
insert @t values ('89546',25)
insert @t values ('78965',85)
insert @t values ('56789',88)
select bj,count(fy) as sl,sum(fy) as hj from (
select *,substring(cast(fy as varchar(10)),1,1) as bj
from @t) a
group by bj
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询