sql取最大值和最小值

2025-04-15 13:22:00
推荐回答(1个)
回答1:

暂时就想到这个笨方法
select a.Date,a.SO2 value,'SO2max'
from table a
where a.SO2 =(select max(SO2)
from table)
union all
select a.Date,a.SO2,'SO2min'
from table a
where a.SO2 =(select min(a.SO2)
from table a)
union all
select a.Date,a.PM2_5 value,'PM2_5max'
from table a
where a.PM2_5 =(select max(PM2_5)
from table)
union all
select a.Date,a.PM2_5,'PM2_5min'
from table a
where a.PM2_5 =(select min(a.PM2_5)
from table a)
union all
select a.Date,a.PM10 value,'PM10max'
from table a
where a.PM10 =(select max(PM10)
from table)
union all
select a.Date,a.PM10,'PM10min'
from table a
where a.PM10 =(select min(a.PM10)
from table a)
union all
select a.Date,a.O3_8h value,'O3_8hmax'
from table a
where a.O3_8h =(select max(O3_8h)
from table)
union all
select a.Date,a.O3_8h,'O3_8hmin'
from table a
where a.O3_8h =(select min(a.O3_8h)
from table a)
...
希望能帮到你,我再想想其他方法,再更新过来。