我运行以下SQL:
SELECT
cusip,
symbol,
CASE WHEN (U1 = 0 OR U2 = 0 OR U3 = 0)
THEN 0 END Universe_Flag,
CASE WHEN (S1 = 'STOP' OR S2 = 'STOP' OR S3 = 'STOP')
THEN 'STOP'
WHEN (S1 = 'ACTIVE' OR S2 = 'ACTIVE' OR S3 = 'ACTIVE')
THEN 'ACTIVE' `enter code here`
END Status
FROM (
SELECT
b.cusip,
b.symbol,
(SELECT UNIVERSE FROM sec_master m WHERE m.CUSIP = b.cusip) U1,
(SELECT UNIVERSE FROM sec_master m WHERE m.SEDOL = b.cusip) U2,
(SELECT UNIVERSE FROM sec_master m WHERE m.CINS = b.cusip) U3,
(SELECT SEC_STATUS FROM sec_master m WHERE m.CUSIP = b.cusip) S1,
(SELECT SEC_STATUS FROM sec_master m WHERE m.SEDOL = b.cusip) S2,
(SELECT SEC_STATUS FROM sec_master m WHERE m.CINS = b.cusip) S3
FROM (
SELECT
e.cusip,
e.symbol
FROM benchmark e
WHERE e.date > DATEADD(month, DATEDIFF(month,0,GETDATE()), 0)
) b
LEFT JOIN sec_master x1
ON x1.CUSIP = b.cusip
AND x1.SEC_STATUS = 'ACTIVE'
AND x1.UNIVERSE = 1
LEFT JOIN sec_master x2
ON x2.SEDOL = b.cusip
AND x2.SEC_STATUS = 'ACTIVE'
AND x2.UNIVERSE = 1
LEFT JOIN sec_master x3
ON x3.CINS = b.cusip
AND x3.SEC_STATUS = 'ACTIVE'
AND x3.UNIVERSE = 1
WHERE x1.SEC_ID IS NULL
AND x2.SEC_ID IS NULL
AND x3.SEC_ID IS NULL
) X
但是返回以下错误:
Msg 512,Level 16,State 1,Line 69 Subquery返回超过1 值。当子查询跟随
=
,!=
,<
,<=
,&gt;时,不允许这样做。>
,>=
或子查询用作表达式时。
答案 0 :(得分:0)
您的SELECT ... FROM sec_master m WHERE ...
之一返回多行。您可以将TOP(1)
与ORDER BY
子句一起使用,或将WHERE
子句中的谓词更改为guarated只获得一行。