列的顺序是否按照分组的顺序重复? [英] Does the order of columns matter in a group by clause?

查看:132
本文介绍了列的顺序是否按照分组的顺序重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有两列,一个基数非常高,另一个基数非常低(唯一值的数量),那么按照我的分组顺序排列吗?



下面是一个例子:

  select 
dimensionName,
dimensionCategory,
sum(someFact )来自SomeFact的
f
在f.dimensionKey上加入SomeDim d = d.dimensionKey
group by
d.dimensionName, - 大量的唯一值
d。 dimensionCategory - 少量的唯一值

是否存在重要的情况?

解决方案

不,订单对GROUP BY子句无关紧要。

MySQL和SQLite是我知道的唯一的数据库,它允许你选择从组中省略的列(非标准,不可移植),但是命令也不重要。


If I have two columns, one with very high cardinality and one with very low cardinality (unique # of values), does it matter in which order I group by?

Here's an example:

select 
     dimensionName, 
     dimensionCategory, 
     sum(someFact)
from SomeFact f
join SomeDim d on f.dimensionKey = d.dimensionKey
group by 
    d.dimensionName,  -- large number of unique values
    d.dimensionCategory -- small number of unique values

Are there situations where it matters?

解决方案

No, the order doesn't matter for the GROUP BY clause.

MySQL and SQLite are the only databases I'm aware of that allow you to select columns which are omitted from the group by (non-standard, not portable) but the order doesn't matter there either.

这篇关于列的顺序是否按照分组的顺序重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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