分组,排序,平均值,最大值,最小值,用sql语句实现
1个回答
展开全部
--创建临时表#temp
create table #temp -- select * from #temp drop table #temp
([name] varchar(36)
,num int)
--插入测试数据
insert into #temp
select 'A','2'
union all
select 'A','3'
union all
select 'B','4'
union all
select 'C','8'
union all
select 'A','6'
--执行操作
select [name]
,avg(num) as [avg]
,max(num) as [max]
,min(num) as [min]
from #temp
group by [name]
order by [name]
--结果
[name] [avg] [max] [min]
A 3 6 2
B 4 4 4
C 8 8 8
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询