原来语句如下
select ( select NO
from Student aa where X_ID in(419) and NO<>a.NO and GROUP=a.GROUP) from Student a
where a.X_ID in(419 ,192,307 ) and a.NO =378
最简单的办法是加 一个top 1 只查询一条,那么如何打印出多条结果呢?
如果出现多个就导致无法操作
子查询返回的值不止一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。 如何直接输出多个
改用CROSS APPLY
SELECT *
FROM Student a
CROSS APPLY (
SELECT NO
FROM Student aa
WHERE X_ID= 419 AND NO <> aNO AND GROUP = a.GROUP
) AS SubQueryResult
WHERE a.X_ID IN (419, 192, 307) AND a.NO = 378
网友评论