mysql group by、select和order by的特例
来源:互联网 发布:招商行情分析软件 编辑:程序博客网 时间:2024/05/22 12:53
1. MySQL具有隐含字段的GROUP BY
在标准的sql中,使用了group by以后,那么select的属性要么在group by中,要么使用聚集函数。对于order by的属性也是这样的。但是对于MySQL数据库扩展了 GROUP BY的用途,因此可以使用SELECT 列表中不出现在GROUP BY语句中的列或运算。这代表 “对该组的任何可能值 ”。可以通过避免排序和对不必要项分组的办法得到它更好的性能。例如,在下列问询中,无须对customer.name 进行分组:
mysql> SELECT order.custid, customer.name, MAX(payments)
-> FROM order,customer
-> WHERE order.custid = customer.custid
-> GROUP BY order.custid;
在MySQL中, 假如不在ANSI模式中运行,则这个名字就是多余的。假如从 GROUP BY 部分省略的列在该组中不是唯一的,那么不要使用这个功能! 会得到非预测性结果(排序结果不稳定)。
具有隐含字段的GROUP BY:http://dev.mysql.com/doc/refman/5.1/zh/functions.html#group-by-functions-and-modifiers
(8)SELECT (9)DISTINCT (11)<Top Num> <select list>
(1)FROM [left_table]
(3)<join_type> JOIN <right_table>
(2) ON <join_condition>
(4)WHERE <where_condition>
(5)GROUP BY <group_by_list>
(6)WITH <CUBE | RollUP>
(7)HAVING <having_condition>
(10)ORDER BY <order_by_list>
select语句中各阶段的执行顺序:http://www.cnblogs.com/laodao1/archive/2010/01/07/1641259.html
http://bbs.csdn.net/topics/390160683
- mysql group by、select和order by的特例
- Mysql的distinct语句和group by,order by
- mysql的order by,group by和distinct优化
- mysql的order by,group by和distinct优化
- mysql的order by,group by和distinct优化
- mysql的group by、order by和having、where比较
- mysql的order by,group by和distinct优化
- mysql的order by,group by和distinct优化
- order by 和 group by 的区别
- order by 和 group by 的区别
- order by和group by的总结
- group by 和order by 的区别
- order by和group by的用法
- order by 和 group by的区别
- order by 和 group by 的区别
- order by 和 group by 的区别
- order by 和 group by 的区别?
- order by和group by
- mysqldump命令详解
- ie6下display:none的BUG
- Ubuntu(乌班图)下mysql+tomcat+jdk+SSH的安装与配置
- 《程序员的第一年》---------- C# 在非web程序取目录笔记
- android 之猜拳游戏练习
- mysql group by、select和order by的特例
- data guard , primary, standy init.ora 备忘
- jdk,jre的关系
- Android优秀开源项目
- 开博了
- Hadoop示例程序WordCount详解及实例
- Linux配置路由表
- windows消息队列
- 如何在mysql中实现update字段set字段=字段+字符