[ 
https://issues.apache.org/jira/browse/CALCITE-5347?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18044542#comment-18044542
 ] 

Zhen Chen commented on CALCITE-5347:
------------------------------------

Hi [~julianhyde], I implemented this feature based on my understanding of Jira. 
If you have time, please review it to see if it meets your expectations. 
Looking forward to your reply.

> Add 'SELECT ... BY', a syntax extension that is shorthand for GROUP BY and 
> ORDER BY
> -----------------------------------------------------------------------------------
>
>                 Key: CALCITE-5347
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5347
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Julian Hyde
>            Priority: Major
>              Labels: pull-request-available
>
> Many people have observed that SQL query syntax is verbose if you want to 
> eliminate duplicates and sort. Business intelligence tools often have query 
> languages that eliminate duplicates and sort by default; we cannot do that in 
> the SQL {{SELECT}} expression, because that would break compatibility. But we 
> propose the following variation of {{SELECT}} that is distinguishable from 
> regular {{SELECT}} (i.e. queries that use it would be invalid in ordinary 
> SQL) but concise and intuitive.
> We propose
> {code:sql}
> SELECT a BY b
> FROM t {code}
> as syntactic sugar for
> {code:sql}
> SELECT b, a
> FROM t
> GROUP BY b
> ORDER BY b{code}
> In the above, {{a}} and {{b}} may be lists of columns, the columns may 
> include aliases, and the columns in {{b}} may include sort-key modifiers such 
> as {{DESC}} and {{NULLS LAST}}.
> For example,
> {code:sql}
> SELECT e.ename, e.empno BY d.dname AS dept DESC, e.job AS title
> FROM Emp AS e
>   JOIN Dept AS d ON e.deptno = d.deptno
> WHERE d.loc = 'CHICAGO'{code}
> is shorthand for
> {code:sql}
> SELECT d.dname AS dept, e.job AS title,
>   e.ename, e.empno
> FROM Emp AS e
>   JOIN Dept AS d ON e.deptno = d.deptno
> WHERE d.loc = 'CHICAGO'
> GROUP BY d.dname, e.job
> ORDER BY d.dname DESC, e.job {code}
>  
> This feature was inspired by [Shakti|https://shakti.com/], a SQL-like 
> language by Arthur Whitney, author of the k language.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to