conditional select statement in oracle

前端 未结 3 1048
借酒劲吻你
借酒劲吻你 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条回答
  •  独厮守ぢ
    2021-01-21 13:24

    Two things to remeber:

    1. ORDER is a keyword, so please use another table name
    2. CASE statement should be ended with END not with END AS

    Possible solution:

    SELECT O.OrderId,
      O.OrderDate,
      CASE
        WHEN H.HolidayDate IS NOT NULL
        THEN 'Public holiday'
        ELSE TO_CHAR(O.OrderDate, 'Day')
      END DAY
    FROM ORDER_TABLE O
    LEFT JOIN HOLIDAY_TABLE H
    ON H.HolidayDate=O.OrderDate;
    

提交回复
热议问题