SQL query with distinct and sum

前端 未结 4 788
天涯浪人
天涯浪人 2020-12-06 04:46

I have the following medleys table that combines colors, fruits and ratings:

[medleys]
medley_id   |   co         


        
4条回答
  •  感动是毒
    2020-12-06 05:33

    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).

提交回复
热议问题