Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想统计某些语言的站点以进行统计并使用此查询:
SELECT `language_id` , count( * ) AS 'num' FROM sites WHERE `language_id` != 0 GROUP BY `language_id` ORDER BY 'num' ASC
但结果不是按num字段排序的。我的 SQL 有什么问题?
num
问题是您num使用单引号'字符引用您的别名,这恰好在创建别名时有效,但在子句中被视为文字字符串ORDER BY:因为它在结果中是不变的,因此不会影响排序顺序。反引号字符在两个子句中都有效。请尝试:
'
ORDER BY
SELECT `language_id` , count( * ) AS `num` FROM sites WHERE `language_id` != 0 GROUP BY `language_id` ORDER BY `num` ASC