开发者

Simple SQL questions, counting and ordering

开发者 https://www.devze.com 2023-04-05 21:23 出处:网络
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 desc

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
0

精彩评论

暂无评论...
验证码 换一张
取 消