0
我想要做的是通過使用WHERE LienType ='No Private'從case語句中創建的Private Benefits別名來縮小查詢範圍。我會怎麼做?在WHERE子句中使用別名SQL
SELECT DISTINCT ClientId
,ClientFirstName
,ClientLastName
, Case when (select COUNT(*)
from FullProductView fpvb
where fpvb.clientid=fpva.clientid
and fpvb.Lientype ='Private Lien') = 0 then 'No Private'
else 'Private Yes' end 'Private Benefits'
from fullproductview fpva
WHERE CaseId = 420
Order By 'Private Benefits'
我認爲,解決他的問題不重複,但查詢的重組: 選擇 \t客戶端Id, \t ClientFirstName, \t ClientLastName, \t CASE \t \t WHEN SUM(CASE WHEN LienType = '私人連戰' THEN 1 ELSE 0 END)> 0 \t \t THEN '私人是' \t \t ELSE '私人否' \t END PrivateBenefits FROM \t FullProductView FPVA WHERE \t CaseId = 420 GROUP BY \t客戶端Id, \t ClientFirstName, \t ClientLastName ORDER BY \t CASE \t \t WHEN SUM(CASE WHEN LienType = '私人連' THEN 1 ELSE 0 END)> 0 \t \t THEN'Private Yes' \t \t ELSE'Private No' \t END; –