2008-11-21

MySQL 查询使用 Group By 的注意点

Views: 11098 | Add Comments
  • If you use GROUP BY, output rows are sorted according to the GROUP BY columns as if you had an ORDER BY for the same columns. To avoid the overhead of sorting that GROUP BY produces, add ORDER BY NULL:

    SELECT a, COUNT(b) FROM test_table GROUP BY a ORDER BY NULL;

-- 载自 MySQL 手册.

上面说的是, group by 默认会排序, 如果不想这么做, 必须显式声明.

Related posts:

  1. MySQL”海量数据”查询性能分析
  2. MySQL查询语句中的引号对索引使用的影响.
  3. 面试IT业界顶尖企业所应该知道的10道题(1)
  4. MySQL binlog查看和清理
  5. MySQL 建立外键约束
Posted by ideawu at 2008-11-21 19:55:32

Leave a Comment