Update multiple rows with averages using mysql -


I'm very close to answering other answers to the answer, but just struggling to get off on the line I am

I have a client table structure that can not be changed, it has several tables, but the two of which I am interested in are (simplified):

Table 1: ID1 (PK), ID2 (PK)), ID3 (PK), AV Girperant (currently blank)

Example:

ID 1, ID 2, id3, avgpcant a, b, c, cord, e, table 2: id 1 (pk), id 2 (pk), id 3 (pk), id 4 (pk), percent

For example A: A, B, C, D, 88, A, B, C, E, 80 A, F, A, B, C, D, G, D, 92

  select ID1, id2, id3, average (percent) ) From Table2 Group ID1, ID2, ID3   

What I need to do is to update Table 1 to fill AVGPresentcent so that it looks like this:

ID1, ID2, ID3, AVGPRC T - A, B, C, 84
E, F, G, 92

I can do this for oddly without line and I table 2 From the average (percent) I can use php and then loop updates through AVGP in the table 1 through 26,000 records, but is there a way to update all the agg-peers in the same tablet?

You can use UPDATE using JOINS as below

 Join  T1 Inner as Update Table 1 (SELECT ID 1, ID2, ID3, Average (Avg) Table 2 Group ID, ID 2, ID 3 as Average) T2 On On T1 ID1 = T.ID1 and T.ID2 = T.ID2 and T.ID3 = T.ID3SETT1 .AVGPercent = t2.AvgPercent   < / Div> 

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -