“分组”自动保证“order by”? [英] Does "group by" automatically guarantee "order by"?

查看:158
本文介绍了“分组”自动保证“order by”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

group by子句是否自动保证结果将按该键排序?换句话说,它是否足够写:

Does "group by" clause automatically guarantee that the results will be ordered by that key? In other words, is it enough to write:

select * 
from table
group by a, b, c

或者必须写

select * 
from table
group by a, b, c
order by a, b, c

我知道eg在MySQL我不必,但我想知道如果我可以依靠它跨越SQL实现。是否保证?

I know e.g. in MySQL I don't have to, but I would like to know if I can rely on it accross the SQL implementations. Is it guaranteed?

推荐答案

group by 。 DB被设计为尽可能快地获取数据,并且仅在必要时进行排序。

group by does not order the data neccessarily. A DB is designed to grab the data as fast as possible and only sort if necessary.

如果您需要有保证的订单,请添加订单

So add the order by if you need a guaranteed order.

这篇关于“分组”自动保证“order by”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆