簡體   English   中英

在SQL中聯接別名和位置

[英]Join Alias and Where in SQL

我正在嘗試運行查詢,我可以在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 Balance = 0
Order by Name

但是像往常一樣,它不能在哪里識別余額?

我們該如何解決?

執行您要問的唯一方法是將該字段放在CTE中,並通過CTE的聯接對其進行引用。

您可以在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