Oracle calculates the maximum value horizontally.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.