sql实现一行中最大值
现有一组数据如下

greatest函数
select name,greatest(x,y,z)max from h3;

提示:一行最小值可以用least
case when写法
select name,case when (case when x > y then x else y end) > z then (case when x > y then x else y end) else z end max from h3;

这个sql相当于java中
int x = 1;
int y = 2;
int z = 3;
int max = x>y?x:y
max=max>z?max:z
如果需要比的字段过多建议使用greatest函数
最后
以上就是激情石头最近收集整理的关于sql实现一行中最大值的全部内容,更多相关sql实现一行中最大值内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复