mysql 判断最大值,最小值,第二大,第三大 一共四个值

如题所述

第1个回答  2012-12-07
最大值:select max(num) from table
第二大值:select max(num) from table
where num not in(select max(num) from table)
第三大值:select max(num) from table
where num not in(select max(num) from table
where num not in(select max(num) from table))
最小值:select min(num) from table本回答被提问者采纳
第2个回答  2012-12-07
最大值
select num from table order by num desc limit 0,1
第二大
select num from table order by num desc limit 1,1
第三大
select num from table order by num desc limit 3,1
最小值
select num from table order by num limit 0,1追问

你好,我是想比如通过判断table表里面某几个字段值(f1,f2,f3,f4)如果是第二大,赋一类值,第三大赋另一类值改怎么写if语句?谢谢

相似回答