Inserting Into Table A Number Of Rows That Equal The Number Of Open Rows If There Are More Than 15 Of Them
My table id sum type 1 3 -1 1 6 -1 1 -6 2 1 -3 1 1 3 -1 1 6 -1 These 1 3 -1 are open rows. Type
Solution 1:
select t.val_id
,t.val_sum
,2 as val_type
from (select val_id
,-abs (val_sum) as val_sum
,sum (case when val_type = -1 then 1 else -1 end) as occurrences
from mytable
group by val_id
,abs (val_sum)
having sum (case when val_type = -1 then 1 else -1 end) > 15
) t
lateral view explode (split (space (cast (occurrences as int) - 1),' ')) e
;
Post a Comment for "Inserting Into Table A Number Of Rows That Equal The Number Of Open Rows If There Are More Than 15 Of Them"