Given an SQL database calle开发者_运维问答d Purchases with columns items and name, will the following query count the number of items ending in 'red' and show the result for each name record in descending order?
SELECT COUNT(item) as "Number of red", Name
FROM Purchases
WHERE item LIKE '%red'
ORDER BY "Number of red items" DESC
This seems to be the query you are looking for.
SELECT COUNT(item) as "Number of red", Name
FROM Purchases
WHERE item LIKE '%red'
GROUP BY Name
ORDER BY COUNT(item) DESC
精彩评论