I project a column in my select statement. ("project" in the relational algebra sense.) With the goal of reducing code duplication, is there a way to reference that projected column in my where clause? Or is there a better way to do that?
Example:
select
(A.Column + A.Column2) * 8 'Column'
from A
where
(A.Column + A.Column2) * 8 < 1000
Basically, what I'm asking, if we think of columns as being "namespaced" by table (where A is a namespace and A.Column is the Column in the A namespace), is: is there a way to refer to the namespace for the ephemeral table we're currently selecting in the where clause of that table itself?
Another way is to use cte, common table expression.
with cte as(
select (A.Column + A.Column2) * 8 as [Column] from A
)
Select * from cte
Where [Column] < 1000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With