SELECT color, fruit, sum(rating)
FROM medleys
GROUP BY color, fruit
Distinct is used to select distinct elements, nothing more, while you want to aggregate and for that you need GROUP BY
and aggregation functions (SUM
).
More Related Contents:
- How do I (or can I) SELECT DISTINCT on multiple columns?
- Why isn’t SQL ANSI-92 standard better adopted over ANSI-89?
- SQL/mysql – Select distinct/UNIQUE but return all columns?
- Is there any difference between GROUP BY and DISTINCT
- Group by minimum value in one field while selecting distinct rows
- How to rewrite IS DISTINCT FROM and IS NOT DISTINCT FROM in SQL Server 20008R2?
- How to use DISTINCT and ORDER BY in same SELECT statement?
- SQL to find the number of distinct values in a column
- Eliminating duplicate values based on only one column of the table
- sql query distinct with Row_Number
- Count Returning blank instead of 0
- MySQL: Select DISTINCT / UNIQUE, but return all columns?
- Huge performance difference when using GROUP BY vs DISTINCT
- Produce DISTINCT values in STRING_AGG
- SQL not a single-group group function
- SQL distinct for 2 fields in a database
- How to select records without duplicate on just one field in SQL?
- ANSI SQL Manual
- SELECT query with CASE condition and SUM()
- Select distinct from multiple fields using sql
- SUM total time in SQL Server [duplicate]
- How can I use SUM() OVER()
- I need help formatting inner join command in SQL query
- Search All Fields In All Tables For A Specific Value (Oracle)
- SQL best practice to deal with default sort order
- How to Create a real one-to-one relationship in SQL Server
- How does GROUP BY work?
- Linq version of SQL “IN” statement
- Core Data Performance with Single Parent Entity
- Historical / auditable database