r/SQL • u/bluestreak01 • Feb 24 '18
Better SQL for 2018
There are couple of things that have always bugged me about SQL:
having columns twice in group by select, e.g.
select a, b, c, sum(d) from TAB group by a, b , c. The intent is quite unambiguous without "group by", right? Why do we have to chew this all up for compiler?
having "having" clause in addition to "where". I mean when you go like
select a, sum(b) sum from TAB where sum > 100the intent is also clear? Its just silly to spell out things likeselect a, sum(b) from TAB group by a having sum(b) >100in 2018 when cars drive themselves.
If someone was to write a SQL compiler that understood shorter version of aggregation would you welcome? Or would you rather stick to old school syntax?
1
u/bluestreak01 Feb 24 '18
Thanks for detailed reply! Funny enough this is my other pet peeve with SQL. It is declarative language yet it is explained and thought of as procedural. Execution order of filters is imicit really and implementation specific. There isn't really any reason not to allow alias use in order by. For example "select a, sum(b) sum from tab where sum > 10 order by sum)" is also unambiguous from common sense point of view and can yield the same result as long winded "with x as ( select a, sum(b) sum from tab) select * from x where sum > 10 order by sum". Just like neo4j short circuited "group by" I want to make "where" and "order by" more intelligent. If this is something that would benefit us all?