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函数
版权声明:本文为qq_43405333原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。