是否基于SQL中的列值添加新行?

时间:2018-06-28 07:38:45

标签: sql vertica

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 

SQL新手,在实现上述目标方面需要一些帮助

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

我怀疑您只想要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;