You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2023/01/10 22:22:19 UTC

[GitHub] [arrow-datafusion] alamb commented on issue #4854: Can not ORDER BY an aliased group column

alamb commented on issue #4854:
URL: https://github.com/apache/arrow-datafusion/issues/4854#issuecomment-1377972610

   cc @jackwener  who may have some ideas
   
   FWIW the logical order of operations is like this (from https://learnsql.com/blog/sql-order-of-operation)
   
   ![image](https://user-images.githubusercontent.com/490673/211674490-041940f2-05d2-453b-b71f-043ada380190.png)
   
   So as you are describing yes the columns which are available to ORDER are the output of the GROUP BY -- so that means either `GROUP BY` columns or aggregates (or some expression of them)
   
   For example, this is valid:
   
   ```sql
   SELECT a,b, sum(c)
   FROM foo
   GROUP BY a, b
   ORDER BY a + b; -- note it is order by a+b (an expression of the group columns)
   -- also note the ORDER BY can not contain `c`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org