Sort by criteria with values from different columns

Source: Internet
Author: User

Sometimes the requirements for sorting are more complex, such as: Leaders are more interested in employees who pay between 1000 and 2000, so employees in this range are required to be in front of them in order to prioritize.

To create a test table:

CREATE OR REPLACE VIEW v asselect ' MARTIN ' as ename, 950 as Sal from Dualunion allselect ' werd ' as ename, 1250 as Sal from Dualunion allselect ' Terner ' as ename, as Sal from Dualunion allselect ' ALLEN ' as ename, and as Sal from Dualunion Allselect ' JAMES ' as ename, 2850 as Sal from DUAL; SELECT * from V;

The SQL code is as follows:

SELECT * from v ORDER by case when Sal between and 1 then ELSE 2 END, Sal;

The results of the implementation are as follows:

Sort by criteria with values from different columns

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.