conditional select statement in oracle

前端 未结 3 1022
借酒劲吻你
借酒劲吻你 2021-01-21 12:43

I have two tables called order and public holiday as following:

Order Table:

OrderId      OrderDate
---------------------------
    1        10 Mar 2017
         


        
3条回答
  •  梦毁少年i
    2021-01-21 13:25

    You can use an outer join like this:

    SELECT OrderId,
           OrderDate, 
           case when holidaydate is not null then  'Public holiday' 
                 else to_char(OrderDate, 'Day') end as DAY
    from orders
         left outer join holidays
            on OrderDate = holiday_date ;
    

    If the dates match holidaydate is not null so the CASE clause displays your desired string otherwise it displays the day of the orderdate .


    order is a reserved word. Presumably your real table has a different name, to avoid the ora-00903 error. I have used orders in my example, so you will need to edit my code to match your table name(s).

提交回复
热议问题