SELECT
[Structure]=mpc.StructureName
,[Type]=CASE pcbor.TypeId
WHEN '0080' THEN 'type1'
WHEN '1845' THEN 'type2'
WHEN '0125' THEN 'type3'
Else 'N/A' END
,Type_De=CASE pcde.TypeId WHEN '0040' THEN 'Type99' Else 'N/A' END
,Type_Ee=CASE pcee.TypeId WHEN '1525' THEN 'Type98'
WHEN '1530' THEN 'Type97' Else 'N/A' END
,Type_Lt=CASE pclt.TypeId WHEN '1525' THEN 'Type96'
WHEN '1530' THEN 'Type95' Else 'N/A' END
FROM [static].[MPC] with (nolock)
JOIN [static].[MPCCenter] mpcpc with (nolock) ON mpcpc.MPCId = mpc.MPCId
JOIN [static].[ProCenter] pc with (nolock) ON pc.ProCenterId = mpcpc.ProCenterId
LEFT JOIN [static].TypeBor pcbor with (nolock) ON pcbor.ProCenterId = pc.ProCenterId
LEFT JOIN [static].Type_De pcde with (nolock) ON pcde.ProCenterId = pc.ProCenterId
LEFT JOIN [static].Type_Ee pcee with (nolock) ON pcee.ProCenterId = pc.ProCenterId
LEFT JOIN [static].Type_Lt pclt with (nolock) ON pclt.ProCenterId = pc.ProCenterId
我的代码有什么问题,因为所有表中都有数据,但我得到的结果是第一个表中的数据(pcbor.typeid),其余的是N / A吗?
答案 0 :(得分:0)
您正在应用左连接,并且您也没有检查Isnull,因为左边连接可能会给出空值,并且'N / A'将在那里,您将连接3个不同的表,每个表返回不同的行ProcenterId,所以'N / A'就在那里
请参阅下面的附加图片(我从您的场景中了解到的内容)。