The usage and similar usage of Oracle case time is to use a field if the A field is not empty, and B field if empty

Source: Internet
Author: User

ID Realname SEX
1 10082 Pine XX
2 10084 Lam xx 1
3 10087 West XX
4 10100 hu xx
5 10102 Dragon xx 1

Usage ============

Select U.id,u.realname,
(Case U.sex
When 1 Then ' Male '
When 2 Then
Female
Else ' empty '
END
) gender
from Users u;

====

In the second case, if the a field is not empty, use the A field, or the B field if it is empty

Select T.epvd_name, T.ff, Count (t.epod_id) from (
Select Epv.epvd_name, Case when To_char (Epod.epod_create_time, ' yyyymm ') are NULL then To_char (Epod.epod_update_time, ' Yyyymm ') ELSE to_char (epod.epod_create_time, ' yyyymm ') END FF, epod.epod_id
From Ep_order_detail ePOD
Left join Ep_vendor epv on epv.epvd_id = epod.vendor_id
where Epod.epod_status > 0
and Epv.epvd_status=1) t

Group BY T.epvd_name, T.ff
ORDER BY T.ff

Note: Aliases cannot be used in this order;

The usage and similar usage of Oracle case time is to use a field if the A field is not empty, and B field if empty

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.