0
Say I have 2 tables:
Table 1
Name - Toys - broken - recurrence
Jack    6      4        0 
John    8      3        1
Mark    8      2        2
Jack    4      2        1
John    3      3        1
Mark    6      0        2

Table 2:
Name  -  Toys  -   recurrence

COlumn Name: name
Column Toys: average of (Jack, John and Mark)'s toys (each a  different record).
Column recurrence: average of the 'broken' field when the recurrence is 1;

My main issue here is how to write a statement to insert data from table 1 
into table 2 with the correct calculations. I was assuming there would be 2
'Where' clauses needed.. but I am not too sure how to write the statement.

I know this will give me the averages in the Toys column per person:
insert into table2 (Toys, recurrence, name) select name,avg(Toys),recurrence from table1
group by name;

But how to I edit this statement so that it will also give me the recurrence column 
which has a different 'where' statement, as in where recurrence='1';
2
Contributors
1
Reply
36
Views
4 Years
Discussion Span
Last Post by LastMitch
0

My main issue here is how to write a statement to insert data from table 1
into table 2 with the correct calculations. I was assuming there would be 2
'Where' clauses needed.. but I am not too sure how to write the statement.

@HDRG

I think you need to learn to write at least a statement to work on, without any effort noones will assist you. So post the statement that you have done so far and show the errors for it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.