Hacker News new | ask | show | jobs
by snidane 1411 days ago

    select product
         , sum(price) as price 
      from table
     where price<1000
    having price>10000

You can refer to the aliased price column before or after aggregation using where or having. Depending on the sql engine.
2 comments

I didn’t know one could still refer to the value before aggregation after it is aliased.

Is there an implicit group by in this query?

This is non-standard and highly dependent on the sql engine. If you believe in portability, your where clauses should (sadly) use the long form.

If that's not a requirement, this approach can add some clarity