Can you do a SELECT by returning the quantity and name of each color?

0

I am making these two queries to download the colors and the quantity of each color in the bike table:

SELECT DISTINCT color FROM bike ORDER BY color ASC
SELECT COUNT(color) FROM bike GROUP BY color ORDER BY color ASC

How do I make the second query, the counts also come with the associated color name, in an array only?

    
asked by anonymous 05.06.2015 / 15:13

1 answer

0

The GROUP BY already guarantees that you will only have one of each color in the output - just pull the two columns at the same time:

SELECT COUNT(*) AS quantidade,
       color
FROM bike
GROUP BY color
ORDER BY color
    
05.06.2015 / 15:37