[英]Identify common rows based on a column value and adding conditions for the grouping in SQL
[英]Adding new rows based on column value in SQL?
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
任何幫助將不勝感激
我懷疑你只想要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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.