Waiting for SQL:202y: Group by All
peter.eisentraut.org
peter.eisentraut.org
select xxxxx as a
, a * 2 as bThough, I think it might have to be table sources, then `SELECT`, then `WHERE`, then ... because you might want to refer to output columns in the `WHERE` clause.
The logical order, in full, is:
FROM
WHERE/JOIN (you can join using WHERE clauses and do FROM a,b still)
SELECT
HAVING
Something like a ‘let’ binding after the FROM/JOIN list would make sense, though - from the query planners perspective it’s nothing more than a token substitution and everything would compile the same.
"select" can also be replaced with annotations, something like: `from table_1 t1 let t1.column_1 as @output_1 where ...` and then just collect all the @-annotated variables.
I need to write a lot of SQL, and it's so clumsy. Every time I need a CTE, I have to look into the documentation for the exact syntax.
Isn't that what a CTE is?
Something like
FROM foo
LET a = (x + y) * z
SELECT a;
whereas CTEs are... Common Table Expressions.https://docs.cloud.google.com/bigquery/docs/reference/standa...
localhost(from SCB-MUSE-BOXX).postgres.scb.5432 [Sun Nov 16 12:02:15 PST 2025]
> create table test (a_key integer primary key, a_group integer, a_val numeric);
CREATE TABLE
Time: 3.102 ms
localhost(from SCB-MUSE-BOXX).postgres.scb.5432 [Sun Nov 16 12:02:25 PST 2025]
> insert into test (a_key, a_group, a_val) values (1, 1, 5.5), (2, 1, 2.6), (3, 2, 1.1), (4, 2, 6.5);
INSERT 0 4
Time: 2.302 ms
localhost(from SCB-MUSE-BOXX).postgres.scb.5432 [Sun Nov 16 12:02:58 PST 2025]
> select a_group AS my_group, sum(a_val) from test group by my_group;
my_group | sum
----------+-----
2 | 7.6
1 | 8.1
(2 rows)
Time: 4.124 ms
localhost(from SCB-MUSE-BOXX).postgres.scb.5432 [Sun Nov 16 12:03:15 PST 2025]
> select a_group AS my_group, sum(a_val) from test group by 1;
my_group | sum
----------+-----
2 | 7.6
1 | 8.1
(2 rows)
Time: 0.360 msit's not something that i've found a particular use for, but it IS a thing you can do.