2014-09-26 55 views
0

我想運行一個查詢,在那裏我可以用where子句加入Alias和凡在SQL

在一個別名例如:

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 

但像往常一樣是不能夠識別欠平衡哪裏?

我們該如何解決這個問題?

+1

使用子查詢,或重複表達或在MySQL中使用having子句。 – 2014-09-26 15:15:42

+0

或者只是在其中重複該操作:'Where A.Order not Null and V.Fees- Coalesce(V.Payment,0) - Coalesce(V.Adjustment,0)= 0' – 2014-09-26 15:17:16

+0

有可能是最好的選擇: http://stackoverflow.com/questions/2905292/where-vs-having – DarkMukke 2014-09-26 15:17:18

回答

0

做你要求的唯一方法就是把這個字段放在CTE中,並通過CTE的加入來引用它。

0

可以重複表達在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 
+0

非常感謝,它幫助。 – 2014-09-26 16:01:30

+0

@soumyasubhraKonar,如果它適合你,你可以接受答案 – radar 2014-09-26 16:11:55