❶ 如何在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