简体   繁体   English

在SQL中联接别名和位置

[英]Join Alias and Where in SQL

I am trying to run a query where i can use an alias in where clause 我正在尝试运行查询,我可以在where子句中使用别名

For example: 例如:

Select V.Fees - Coalesce(V.Payment,0) - Coalesce (V.Adjustment,0) AS Balance
[
the inner join query for the tables
]
Where A.Order not Null and Balance = 0
Order by Name

but as usual it is not able to recognize Balance under where? 但是像往常一样,它不能在哪里识别余额?

How can we fix this? 我们该如何解决?

执行您要问的唯一方法是将该字段放在CTE中,并通过CTE的联接对其进行引用。

you can repeat the expression in the where clause 您可以在where子句中重复该表达式

Select V.Fees - Coalesce(V.Payment,0) - Coalesce (V.Adjustment,0) AS Balance
[
the inner join query for the tables
]
Where A.Order not Null and (V.Fees - Coalesce(V.Payment,0) - Coalesce (V.Adjustment,0)) = 0
Order by Name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM