SQLite Forum

meaning of "GROUP BY CONSTANT"
Login
I always knew you could specify positions in ORDER BY, but I did not know about GROUP BY.

This is very useful for exploring data.  Thanks.  I often have long complicated expressions for GROUP BY.

I vaguely recall there is a reason why this is not implemented in, say, Oracle, for example, that there is some ambiguity that arises, but thinking about it now I cannot see any problem with it.

By experiment, it appears I can also use a column alias in the GROUP BY that is defined in the SELECT.  Again, I vaguely recall there is a reason why this is not implemented in many SQL engines.  In this case, I am pretty sure ambiguities can arise.  It's a question of scope.  For example, I can swap the names of two columns using something like:

SELECT A AS B, B AS A FROM .....;

In this case, does GROUP BY A refer to the original column name or the alias?  In the case of ORDER BY, I think the alias has precedence.

Anyway, the position notation should be documented in GROUP BY.  Should I try to write an edit for the documentation?