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

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

最大值: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

select max(字段名) from tableName limit 0,1 最大

select min(字段名) from tableName limit 0,1 最小

select * from tableName order by 字段名 DESC limit 0,1 最大

select * from tableName order by 字段名 ASC limit 0,1 最小

给你举个例子,你自己按照你所在当前表的情况来进行查询。例如:select 列1 avg(列2) as xz from 表 group by 列1 order by xz desc 解释:avg()函数是求某列的平均值,group by是对某列分组,按照SQL标准,分组要和聚合函数一起配合使用才有意义[虽然在mysql中不会报错]。order by xz desc表示的是对xz进行降序,就可以把最高的平均值算出来。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6209173.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-18
下一篇 2023-03-18

发表评论

登录后才能评论

评论列表(0条)

保存