从查询结果中继续查询

SELECT * FROM
(
SELECT a.*,b.BelongFloor,c.id AS UnitID,c.housename AS UnitName FROM [CRM_HouseInfo] a
LEFT JOIN [CRM_RoomInfo] b ON a.[ID]=b.[HouseID]
LEFT JOIN CRM_HouseInfo c ON a.[ParentID]=c.id AND c.reskind=4
WHERE
a.AncestorID like '%|'+convert(varchar(20),177)+'|%'
AND a.[ResKind]<>4
) b

注意:必须有指定b,否则出错

你可能感兴趣的:(查询)