-2
Comment         weekid  acc1    acc2    acc3    acc4       value
----------------------------------------------------------------------------------
Current data        1   a      b       c       d             2
Current data        1   a      b       c       e             3
Line to be added    1   a      b       c       Fixed New     value of d/value of e 

Any help will be greatly appreciated

Dale K
  • 25,246
  • 15
  • 42
  • 71
kkoc3
  • 69
  • 1
  • 7
  • What's your dbms and your expect result, sample data?that really help – D-Shih Jun 28 '18 at 07:41
  • we are using vertica expected result is i need to add that last line where its says line to be added in comment field – kkoc3 Jun 28 '18 at 07:42

1 Answers1

0

I suspect you just want union all:

select weekid, acc1, acc2, acc3, acc4, value
from t
union all
select weekid, acc1, acc2, acc3, 'Fixed new' as acc4,
       ( max(case when acc4 = 'd' then value end) /
         max(case when acc4 = 'e' then value end)
       ) as value
from t
group by weekid, acc1, acc2, acc3;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786