给定一个名为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
答案 0 :(得分:2)
这似乎是您正在寻找的查询。
SELECT COUNT(item) as "Number of red", Name
FROM Purchases
WHERE item LIKE '%red'
GROUP BY Name
ORDER BY COUNT(item) DESC