sql - Copy one column value to another -


i have table has following values

 sno     package  id  66      250     111  66       0      100  66       0      99  66       0      88  67      270     225  67      267     111  67      0       35  68      230     111  68      225     250  68      0       210 

now want value of package 0 put value of package id 111 ie 66: 250, 67: 267, 68: 230

the following result

sno    value     id     66     250      111 66     250      100 66     250      99 66     250      88 67     270      225 67     267      111 67     267      35   68     230      111 68     225      250 68     230      230 68     230      210 

i applying of queries

select sno, case age when 0 (select age table1 id=111 )                      else 1 end age, id table1 

this internal subquery gives more 1 value, cannot hardcode using sno. how can done?. please using groupby clause or joins or cursor.

thanks

i think of "looking up" age in table, when age 0. this, structure query as:

select sno, (case when t.age = 0 lookup.age else t.age end) age, id table1 t left outer join      (select *       t       id = 111      ) lookup      on t.sno = lookup.sno; 

the left outer join ensure no rows lost if there no "111" row. subquery clear logic in query.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -