【发布时间】:2012-10-13 10:02:54
【问题描述】:
SELECT
Trade.TradeId,
Isnull(Securities.SecurityType,'Other') SecurityType,
TableName,
CASE
WHEN
SecurityTrade.SecurityId IS NOT NULL
THEN
SecurityTrade.SecurityId
ELSE
Trade.SecurityId
END AS PricingSecurityID,
sum(Trade.Quantity)OVER(Partition by Securities.SecurityType, SecurityTrade.SecurityId,Trade.Price, Buy,Long ) as sumQuantity,
--added porfolio id for Getsumofqantity
Trade.PortfolioId,
Trade.Price,
case
when (Buy = 1 and Long = 1) then 1
when (Buy = 0 and Long = 0) then 1
else 0
end Position
from
Fireball_Reporting..Trade
where porfolioid =5 and Position =1
我想在 where 子句中使用 Position =1,它是 case 的别名
case
when (Buy = 1 and Long = 1) then 1
when (Buy = 0 and Long = 0) then 1
else 0
end Position
如何在 where 子句中使用它?
我试过 zo 直接在 where 子句中使用那个 CASE 语句,但是失败了。
WHERE Trade.SecurityId = @SecurityId AND PortfolioId = @GHPortfolioID AND
(case when (Buy = 1 and Long = 1) then 1 when (Buy = 0 and Long = 0) then 1 else 0 end Position = 1)
【问题讨论】:
-
你不能,除非你在外部查询中添加另一个选择并检查 postion = 1。
-
您使用的是什么 SQL 语言?
-
sql server 2008 中的 T SQL
标签: sql sql-server qtsql