简单的SQL问题,计数和排序

时间:2011-09-20 08:32:45

标签: sql

给定一个名为Purchases with the items items and name的SQL数据库,以下查询是否会计算以'red'结尾的项目数,并按降序显示每个名称记录的结果?

SELECT COUNT(item) as "Number of red", Name 
FROM Purchases 
WHERE item LIKE '%red' 
ORDER BY "Number of red items" DESC

1 个答案:

答案 0 :(得分:2)

这似乎是您正在寻找的查询。

SELECT COUNT(item) as "Number of red", Name
FROM Purchases
WHERE item LIKE '%red'
GROUP BY Name
ORDER BY COUNT(item) DESC