这是我当前的 SQL 查询。我需要修改这个
SELECT
18 BrokerDealerID,
5 PortfolioID,
PeriodEndDate DATE,
SecurityIdentifier_All.SecurityId,
MAX(
(CASE
WHEN Securities.Quantity < 0 THEN
100 + (100 - LocalPriceAmount)
ELSE
LocalPriceAmount
END
) /100) Mark
FROM
Fireball_Reporting..StateStreet_DailyPosition_Second StateStreet
INNER JOIN
Fireball_Reporting..SecurityIdentifier_All ON StateStreet.CUSIP = SecurityIdentifier_All.Identifier
INNER JOIN
Fireball..TradeBySecurityType Securities ON
Securities.PricingSecurityID = SecurityIdentifier_All.SecurityId AND Securities.Position = 1 AND
(CASE WHEN StateStreet.SecurityName LIKE '% R V %' THEN StateStreet.SharesParValue * -1 ELSE StateStreet.SharesParValue END) = Securities.Quantity
WHERE
CONVERT(DATETIME, StateStreet.PeriodEndDate) = '2012-10-23' --@PositionDate
GROUP BY
PeriodEndDate,
SecurityIdentifier_All.SecurityId
我需要在第二个条件下进行更改,即
(CASE WHEN StateStreet.SecurityName LIKE '% R V %' THEN StateStreet.SharesParValue * -1 ELSE StateStreet.SharesParValue END) = Securities.Quantity
我会给你一个例子。
我的选择查询给了我以下输出
securityname date securityid portfolioid type mark quantity
------------ ---------- ---------- ----------- ---- ------------------ -------------
R V DISH 10/23/2012 4879505 5 CDS 1.0487189900000000 -5000000.0000
R V DISH 10/23/2012 4879505 5 CDS 1.0487189900000000 -2000000.0000
R F DISH 10/23/2012 4879505 5 CDS 0.9512810100000000 3000000.0000
上面它给了我 3 条相同安全 ID 的记录当我使用上述结果进行 MERGE 时,如果我不检查检查的第二个条件,它只会直接获取第一条记录,Quantity
但现在我只想检查 When In StateStreet。 SecurityName LIKE '% RV %' 从上述结果中取出数量为-
的记录,如果不是,则取出数量为 id 的记录+
我怎么能改变那个案例陈述?% R V%
还是直接在我计算标记的选择语句中检查?需要技术帮助。我是 SQL 新手。