How Oracle can remove the maximum and minimum values from multiple field columns

Source: Internet
Author: User
Tags min

First, two functions are introduced (two connections below):

Oracle least () function

Oracle Greatest () function

Example:

To build a table statement:

CREATE TABLE EMP  
(  
  EMPNO number    (4) Not NULL,  
  ename    VARCHAR2 (Ten),  
  JOB      VARCHAR2 (9),  
  MGR number      (4),  
  hiredate DATE,  
  SAL number      (7,2),  
  COMM number     (7,2),  
  DEPTNO   Number (2)  
)

If you require empno, mgr,sal the maximum and minimum values in the three columns, the code is as follows:

SELECT EMPNO, Mgr,sal,  
      Greatest (EMPNO, Mgr,sal) max,  
      least (EMPNO, mgr,sal) min from
emp

The results are shown below:

If you want to display only the largest and smallest rows, the code is as follows:

SELECT EMPNO, Mgr,sal,  
      Greatest (EMPNO, Mgr,sal) max,  
      least (EMPNO, mgr,sal) min from
 emp where rownum< 2;

The effect is as follows:

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/

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.