Wednesday, 15 September 2010

mysql - Best way to update over 12 million record Loop or no loop -


I have more than 12 million records in my table with more than 6000 stock figures for the past 15 years. I << html>

Trying to update please see the sample table below. The only way I can think of updating the price of tomorrow is using the script language. I am using C # to loop through all the records. The first loop is to get all the symbols, the second loop through each symbol from the first loop, and update the price of tomorrow one day before tomorrow. It takes a very long time any ideas, new approaches, and other approaches that speed up the process?

  symbol, today, value, price of tomorrow ---- --------- ----- - ------ AAPL, 5/13 / 2015, 123.59, 124.45 Apple, 5/12/2015, 124.45, 122.24 Apple, 5/11/2015, 122.24, Apple does not know, 5/10/2015, 127.41, do not know  
< / Div>

You update this single SQL statement, like this:

  Update MyTableT Join Left Outter MyTable y on y.Symbol = t.Symbol and t.todayis = subdate (y.todayis, 1) SET a.yesterdayprice = COALESCE (y.price, 'do not know')  

This attempts to execute a self-contained UPDATE , symbols And computing via yesterday's date subdate (y.todayis, 1) ( t means "today", y < / Code> for "tomorrow").

When the associated row is found, COALESCE provides value for updates from when the row is not there, then 'unknown' string Is used as the default.


No comments:

Post a Comment