|
|
|
|
|
by wenc
2075 days ago
|
|
I consider myself a fan of SQL, but my nitpick is more around named calculated columns. For instance: SELECT AVG(col1) OVER (PARTITION BY col2) AS partcol1
FROM tbl
WHERE AVG(col1) OVER (PARTITION BY col2) > 10.0
I wish I could just do: SELECT AVG(col1) OVER (PARTITION BY col2) AS partcol1
FROM tbl
WHERE partcol1 > 10.0
But I can't, because the WHERE clause is processed before the SELECT clause.So if I have a bunch of these and want a convenient way to work with the named columns, I have to wrap them into a common table expression: WITH cte AS (
SELECT AVG(col1) OVER (PARTITION BY col2) AS partcol1
FROM tbl
)
SELECT partcol1
FROM cte
WHERE partcol1 > 10.0
So wordy. |
|
For example, your example would have been more naturally expressed as