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
Post a Comment