In the recent development process, we need to take the maximum value of the horizontal column in Oracle. Here we will introduce several Oracle functions for you:
For more information, see the blog. If you have any help, please leave a trace!
Oracle vertical maximum function: max (), minimum function: min ()
The maximum value is greatest () and the minimum value is least ()
Returns the maximum value of a certain number of columns.
Select greatest (col1, col2, col3. ..) from tablename;
Returns the minimum value of a certain number of columns.
Select least (col1, col2, col3. ..) from tablename;
The syntax for obtaining the horizontal maximum and minimum values in SQL Server is complicated. The vertical method is the same as that in Oracle. I will not introduce it here:
See http://topic.csdn.net/t/20060404/18/4662908.html
Create Function DBO. f_max (
@ Col1 int, @ col2 int, @ col3 int, @ col4 int, @ col5 int
) Returns int
As
Begin
Return (select max (COL) from (
Select Col = @ col1 Union
Select @ col2 Union
Select @ col3 Union
Select @ col4 Union
Select @ col5 )))
End
Go
Create Function DBO. f_min (
@ Col1 int, @ col2 int, @ col3 int, @ col4 int, @ col5 int
) Returns int
As
Begin
Return (select Min (COL) from (
Select Col = @ col1 Union
Select @ col2 Union
Select @ col3 Union
Select @ col4 Union
Select @ col5 )))
End
Go
-- Call functions for processing
Select DBO. f_max (A1, A2, A3, A4, A5 ),
DBO. f_min (A1, A2, A3, A4, A5)
From TB