I'm trying to run a query that sums up data for a certain value. It's summing up the data correctly but it's returning duplicate output because the value exists in the table more than once. I tried using distinctrow but got this error message:
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
Here's the initial query that returns duplicates:
SELECT SUM(field1) as sales,SUM(field2) as cost, AVG(field3) as avgLength FROM table WHERE field4='$field4'
Here's some sample data:
field1 field2 field3 field4
100 10 5 something
110 15 3 something
50 5 5 somethingelse
Here's some sample output:
something 210 25 8
something 210 25 8
something else 50 5 5