比如: 某个表
A B C D
1 2 3 4
2 3 6 7
3 5 4 9
4 3 8 9
结果
maxnum
9
9
7
4
现在需要先找出行中 A B C D最大的,然后所有的字段再排序。
不用临时表转为单一字段比较,有没有比较简单的方法,比如MAX()函数什么的!
------解决方案--------------------
- SQL code
create function getmax(@a int,@b int,@c int,@d int)returns intasbegin if @a<@b set @a = @b if @a<@c set @a = @c if @a<@d set @a = @d return @aendgoselect dbo.getmax(a,b,c,d) from tb