我的子查询返回的值超过1,为什么?

时间:2015-12-08 22:09:14

标签: sql-server

Subquery返回的值超过1。当subquery跟随=!=<<=>>=subquery用作表达式。

select 
(SELECT persFName + ' ' + persLName FROM person WHERE persGender = 'M') AS 'Father',
(SELECT persFName + ' ' + persLName FROM person WHERE persGender = 'F') AS 'Mother'

是我的代码,为什么不会输出

1 个答案:

答案 0 :(得分:1)

也许就像....

select CASE WHEN persGender = 'M' THEN persFName + ' ' + persLName END AS [Father]
     , CASE WHEN persGender = 'F' THEN persFName + ' ' + persLName END AS [Mother]
FROM person 
WHERE persGender IN ('M', 'F')