sql: support HAVING without GROUP BY clause
Allowed to make SELECT requests that have HAVING clause without GROUP BY. It is possible when both - left and right parts of request have aggregate function or constant value. Closes #2364. @TarantoolBot document Title: HAVING without GROUP BY clause A query with a having clause should also have a group by clause. If you omit group by, all the rows not excluded by the where clause return as a single group. Because no grouping is performed between the where and having clauses, they cannot act independently of each other. Having acts like where because it affects the rows in a single group rather than groups, except the having clause can still use aggregates. Having without group by is not supported for select from multiple tables. 2011 SQL standard "Part 2: Foundation" 7.10 <having clause> p.381 Example: SELECT MIN(s1) FROM te40 HAVING SUM(s1) > 0; -- is valid SELECT 1 FROM te40 HAVING SUM(s1) > 0; -- is valid SELECT NULL FROM te40 HAVING SUM(s1) > 0; -- is valid SELECT date() FROM te40 HAVING SUM(s1) > 0; -- is valid
Showing
- src/box/sql/resolve.c 70 additions, 19 deletionssrc/box/sql/resolve.c
- src/box/sql/sqliteInt.h 2 additions, 1 deletionsrc/box/sql/sqliteInt.h
- test/sql-tap/count.test.lua 4 additions, 4 deletionstest/sql-tap/count.test.lua
- test/sql-tap/select3.test.lua 1 addition, 1 deletiontest/sql-tap/select3.test.lua
- test/sql-tap/select5.test.lua 127 additions, 1 deletiontest/sql-tap/select5.test.lua
Loading