Example of Oracle sorting by conditions

Source: Internet
Author: User

Requirement: the number of appointment cases on the current day is at the beginning --> the number of cases that have never been handled --> the last handling time is sorted from small to large (that is, the closer the collection is, the more the case is later)

That is: (col_case.case_app_date = sysdate) --> (col_case.case_lst_col_date is null) --> (col_case.case_lst_col_date)

Select case when trunc (T. case_app_date) = trunc (sysdate) Then '1'
When T. case_lst_col_date_str is null then '2'
Else '3' end as column1, T .*
From
(
Select v_coloverview_full. * From v_coloverview_full where mcol_id = 'hangq'
Or (agent_id = 'zhangq' and agent_status = 'agentstatus _ agree'
And agent_date_from <= sysdate and agent_date_to> = sysdate)
)
T
Order by column1, case_lst_col_date_str ASC

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.