Add similar IFS function to query with sub-query (oracle sql) -


this part of query. want add column called missed if impact label 1 , hours > 8 -> missed, impact 2 hours > 14 -> missed , impact 3 hours > 80 -> missed. please help. thanks!

  select   o.create_datetime   ,o.resolved_datetime   ,24 * (to_date(resolved_datetime, 'yyyy/mm/dd hh24:mi:ss')               - to_date(create_datetime, 'yyyy/mm/dd hh24:mi:ss')) hours    ,o.item   ,o.impact_label    (select         ,to_char(create_date,'yyyy/mm/dd hh24:mi:ss') create_datetime       ,to_char(resolved_date,'yyyy/mm/dd hh24:mi:ss') resolved_datetime       ,status       ,(case impact_label         when '1 - ' '1'         when '2 - ' '2'         when '3 - ' '3'         when '4 - ' '4'         when '5 - ' '5'         else null         end) impact_label             table )o 

i'd re-write using "with" clauses, that's me .. :) need layer in there user calculated columns ...

try this:

  w_o (      select          ,to_char(create_date,'yyyy/mm/dd hh24:mi:ss') create_datetime         ,to_char(resolved_date,'yyyy/mm/dd hh24:mi:ss') resolved_datetime         ,status         ,(case impact_label           when '1 - ' '1'           when '2 - ' '2'           when '3 - ' '3'           when '4 - ' '4'           when '5 - ' '5'           else null           end) impact_label                      table         ),      w_sub (            select               o.create_datetime              ,o.resolved_datetime              ,24 * (to_date(resolved_datetime, 'yyyy/mm/dd hh24:mi:ss')                          - to_date(create_datetime, 'yyyy/mm/dd hh24:mi:ss')) hours               ,o.item              ,o.impact_label            w_o         )   select create_datetime,          resolved_datetime,          hours,          item,          impact_label,          case when impact_label = '1' , hours > 8                  'missed'               when impact_label = '2' , hours > 14                  'missed'               when impact_label = '3' , hours > 80                  'missed'               else                  'hit?'            end  missed   / 

this new part, rest same have, re arranged clauses .. ;)

         case when impact_label = '1' , hours > 8                  'missed'               when impact_label = '2' , hours > 14                  'missed'               when impact_label = '3' , hours > 80                  'missed'               else                  'hit?'            end  missed 

you combine case clauses using or, however, clearer read , follow ... either way ...


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -