mysql - refering a calculated value in another column -


i'm trying make calculated value show in column in table. can please explain why doesn't work

create table #medition (id int,avg decimal(18,4)) insert #medition (id, avg)  select id, sum(125hz + 250hz + 500hz + 750hz + 1000hz + 1500hz + 2000hz + 3000hz + 4000hz + 6000hz + 8000hz)/11 avg tonvarden  update matningar  set matningar.tonmedelvarde = #medition.avg matningar inner join #medition on matningar.id =#medition.id  drop table #medition 

i getting error

#1064 - have error in sql syntax; check manual corresponds mysql server version right syntax use near 'insert #medition (id, avg) select id, sum(125hz + 250hz + 500hz + 750hz + ' @ line 2 

no need create temporary table this.

update matningar join tonvarden b on a.id = b.id set a.tonmedelvarde = (`125hz` + `250hz` + `500hz` + `750hz` + `1000hz` +                            `1500hz` + `2000hz` + `3000hz` + `4000hz` + `6000hz` +                            `8000hz`)/11; 

if update matningar whenever new row inserted tonvarden, can create following trigger:

create trigger update_matningar before insert on tonvarden each row  update matningar  set tonmedelvarde =      (new.`125hz` + new.`250hz` + new.`500hz` + new.`750hz`          + new.`1000hz` + new.`1500hz` + new.`2000hz`          + new.`3000hz` + new.`4000hz` + new.`6000hz`          + new.`8000hz`)/11 id = new.id; 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -