I have a dataset which is not set out the best way see a sample of it below.
col1|col2|col3
john smith|10|3
tom smith|8|3
sean smith|12|3
sean smith|5|33
john smith|3|32
john smith|6|13
As you can see col1 has multiple records that are the same.
I want to be able to group all the entries with the same value in col1 and output then into the one row I also want to display another column which is the sum of col2*col3 so that my output would look like the below.
col1|col2|col3
john smith|19|48|912
sean smith|17|36|612
tom smith|8|3|24
Would it be best to use mySQL Sum here? How can I write this select statement when I don't know what 'WHERE' will be but I just want it to output the result for each name?
You can do like this too ::
Select
col1, SUM(col2), SUM(col3), SUM(col3)*SUM(col2)
from table group by col1
Try this::
Select
col1, SUM(col2) as b, SUM(col3) as c, SUM(col2)*SUM(col3) as d
from table group by col1
Try this:
SELECT col1,SUM(col2),SUM(col3),SUM(col2)*SUM(col3) FROM table
GROUP BY col1