当前位置:首页 » 编程语言 » sql统计最大值最小值
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql统计最大值最小值

发布时间: 2022-11-08 06:49:03

❶ 如何在sql中查询最大值与最小值

select max(气温),min(气温) from 气温表;
哈哈

❷ sql取最大值和最小值

select
g_table.max_so2
,t_so2.date
,g_table.min_so2
,t_so2_min.date
....
(
select
max(so2) max_so2
,min(so2) min_so2
,max(pm2.5) max_pm25
,min(pm2.5) min_pm25
...
,max(co) max_no2
,min(co) min_co
from table_name
) g_table
,table_name t_so2
,table_name t_so2_min
...
where g_table.max_so2 = t_so2.so2(+)
and g_table.min_so2 = t_so2_min.so2(+)
....

你这个需求有点费劲,这样能实现,但是效率很低。

❸ 如何使用sql函数平均值、总数、最小值、最大值、总和、标准差

avg函数:计算查询中某一特定字段资料的算术平均值。
count函数:计算符合查询条件的记录数。
min, max函数:传回指定字段值中符合查询条件的第一条、最末条记录的资料。
first, last函数:传回指定字段值中符合查询条件的最小值、最大值。
stdev函数:计算指定字段值中符合查询条件的标准差。
sum函数:计算指定字段值中符合查询条件的资料总和。
var,函数:计算指定字段值中符合查询条件的变异数估计值。

❹ 用SQL语句查询最小值,最大值不能用min,max函数怎么查

1.
--大于等于所有(最大值)
select*fromApo_city
wherecity_id>=all(selectcity_idfromApo_city)
--小于等于所有(最小值)
select*fromApo_city
wherecity_id<=all(selectcity_idfromApo_city)

--2.
--降序取第一个(最大值)
select*fromApo_city
wherecity_id=(selecttop1city_idfromApo_cityorderbycity_iddesc)
--升序取第一个(最小值)
select*fromApo_city
wherecity_id=(selecttop1city_idfromApo_cityorderbycity_idAsc)

--3.
--最大值
selectTop1city_idfromApo_cityorderbycity_iddesc
--最小值
selectTop1city_idfromApo_cityorderbycity_idAsc

--4.
--最大值
WithT
As
(
select*,ROW_NUMBER()over(orderbycity_idDesc)asidfromApo_city
)
select*fromTwhereid=1
--最小值
WithT
As
(
select*,ROW_NUMBER()over(orderbycity_idAsc)asidfromApo_city
)
select*fromTwhereid=1

5.
--不小于任何一个(最大值)
select*fromApo_city
wherenotcity_id<any(selectcity_idfromApo_city)

--不大于任何一个(最小值)
select*fromApo_city
wherenotcity_id>any(selectcity_idfromApo_city)

❺ 如何用sql语句查出最大值、最小值等

select '最大温度值' as 描述,t as 值,datetime from test where t in(select max(t) from test )
union
select '最小温度值' as 描述,t as 值,datetime from test where t in(select min(t) from test )
union
select '最大湿度值' as 描述,p as 值,datetime from test where p in(select max(p) from test )
union
select '最小湿度值' as 描述,p as 值,datetime from test where p in(select min(p) from test )

test 改成你的表名

❻ SQL语句求一个表中两列数据中的最大/最小值/标准差



selectcase(
whenMAX(col1)>MAX(col2)then'col1大'
whenMAX(col1)<MAX(col2)then'col2大'
else'相等'end)asCOL1,
case(
whenMIN(col1)<MIN(col2)then'col1小'
whenMIN(col1)>MIN(col2)then'col2小'
else'相等'end)asCOL2,
case(
whenavg(col1)<avg(col2)then'col1品均小与col2'
whenavg(col1)>avg(col2)then'col2品均小与col1'
else'相等'end)asCOL3
fromtable1