sql 查询一行内几列的平均值,最大值,最小值,怎么写
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/10/02 17:54:06
sql 查询一行内几列的平均值,最大值,最小值,怎么写
比如 name 1 2 6 7 9 0 3
求 1,2,6,7,9,0,3这几个值的最大最小平均值
比如 name 1 2 6 7 9 0 3
求 1,2,6,7,9,0,3这几个值的最大最小平均值
oracle的话直接用greatest函数,sql server的话照这么写:
select t1.name,max(t1.a) maxnum,min(t1.a) minnum,avg(t1.a) avgnum from
(select name,num1 a from tb1
union all
select name,num2 a from tb1
union all
select name,num3 a from tb1
union all
select name,num4 a from tb1
union all
select name,num5 a from tb1
union all
select name,num6 a from tb1
union all
select name,num7 a from tb1) t1
group by t1.name;
测试数据:
create table tb1(name varchar(50),num1 int,num2 int,num3 int,num4 int,num5 int,num6 int,num7 int)
insert into tb1 select 'Tom',1,2,6,7,9,0,3
insert into tb1 select 'Jacky',7,6,5,4,3,2,1
结果:
name maxnum minnum avgnum
Jacky 7 1 4
Tom 9 0 4
select t1.name,max(t1.a) maxnum,min(t1.a) minnum,avg(t1.a) avgnum from
(select name,num1 a from tb1
union all
select name,num2 a from tb1
union all
select name,num3 a from tb1
union all
select name,num4 a from tb1
union all
select name,num5 a from tb1
union all
select name,num6 a from tb1
union all
select name,num7 a from tb1) t1
group by t1.name;
测试数据:
create table tb1(name varchar(50),num1 int,num2 int,num3 int,num4 int,num5 int,num6 int,num7 int)
insert into tb1 select 'Tom',1,2,6,7,9,0,3
insert into tb1 select 'Jacky',7,6,5,4,3,2,1
结果:
name maxnum minnum avgnum
Jacky 7 1 4
Tom 9 0 4
sql 查询一行内几列的平均值,最大值,最小值,怎么写
sql语句,同时查询某记录的平均值,最大值,最小值及最大值时间,最小值时间.
我想问下一句查询最大值与最小值的sql语句
sql语句:去掉最大值,去掉最小值,算平均值
用SQL语句查询最小值、最大值不能用min、max函数怎么查啊?
excel2007 怎么实现一行的单元格下拉菜单里有各种函数运算,如求和,最大值最小值,平均值之类的
EXCEL怎么统计一堆数据中的最小值的平均值和最大值的平均值
英语翻译去掉最大值和最小值的平均值叫什么平均值?用英语怎么翻译?
如何用excel计算并比较一行或一列中各段空值的个数,得出“最大值,最小值,平均值”?
知道最小值最大值 怎么求平均值和标准差?
一组数据的最大值和最小值的平均值是什么
简单的指针求最大值最小值平均值问题