sql - Can I Insert a Particular Value to Replace the First Non-NULL Value in Each Row -


enter image description here have table above. insert particular value, called i1,i2,i3,...,i10. first non-null value. value want insert vary based on duration first non-null value lies.

for example, first non-null value id1 duration 3, insert "i3" particular cell. id 2, want insert i2 cell,etc.

there result expect enter image description here

i1,i2,i3,...,i10 industrial value have @ hand, numbers not characters.

is there way that? thank you.

you can simple update using case expressions:

update mytable set     duration1 = case when duration1 not null i1 else duration1 end ,   duration2 = case when duration1 null , duration2 not null i2 else duration2 end ,   duration3 = case when duration1 null , duration2 null , duration3 not null i3 else duration3 end -- continue in same boring way ,   duration10 = case when duration1 null , duration2 null , duration3 null , duration4 null , duration5 null , duration6 null , duration7 null , duration8 null , duration9 null , duration10 not null i10 else duration10 end 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -