3 ms·
select product , sum(price) as price from table where price<1000 having price>10000 You can refer to the aliased price column before o
by snidane 4y 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.
- occamrazor 4y agoI 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?
- mwexler 4y agoThis 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