How can we improve SQL Prompt?

Automatically generate the GROUP BY column list from the SELECT list

Typically, the GROUP BY column list is exactly the same as the SELECT list except the aggregates and any constants included. I usually wind up using a copy & paste, which is always a hassle, especially if it is a complex query. It always seemed to me that the GROUP BY list should be optional in the SQL standard. But short of a standard change followed by implementation changes, it would be nice to at least have it defaulted for me.

By the same token, the HAVING statement could (optionally) prepopulate with (one of) the aggregate(s) from the select list. But the GROUP BY list is usually the main hassle.

In fact, many of my statements with a GROUP BY clause, will have the same column list in SELECT, GROUP BY, and ORDER BY (if I include an ORDER BY), and others will order by the aggregate - usually in descending order.

42 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Tore BostrupTore Bostrup shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base