mysql update one table from another -


i have massive database on over 2.7 million rows. contains data on uk property prices.

the first table called pricepaid , has column called price , loc4.

now trying average each year grouped loc4 , update tabel called pricepaidbycounty.

i have created sql statement :

insert pricepaidbycounty (county, avg2013) select loc4, avg(price) avgprice2013 pricepaid date '%2013%' group loc4 

this works fine inserting initial row want use update statement instead need run sql query each month.

can show me how change insert update.

i doing need display average house price each location year. , database big dont want on flu

thanks

you can update table using following query using insert ... on duplicate key update statement (https://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html):

insert pricepaidbycounty (county, avg2013) select loc4, avg(price) avgprice2013  pricepaid  date '%2013%'  group loc4 on duplicate key update avg2013=avgprice2013 

for work need make sure set of (county, avg2013) defined unique key.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -