34,588
社区成员
发帖
与我相关
我的任务
分享
--如果改为
a.bParent = b.bId where a.bId=14 ) as aa
--你应该就懂了。
select * from
(SELECT a.* FROM Ay_Class AS a where a.bId=14
union
select b.* from Ay_Class AS a
INNER JOIN Ay_Class AS b ON a.bParent = b.bId where a.bId=14 ) aa
order by bParent,bOrder
select * from
(SELECT a.* FROM Ay_Class AS a where a.bId=14
union
select b.* from Ay_Class AS a
INNER JOIN Ay_Class AS b ON a.bParent = b.bId where a.bId=14 )
order by bParent,bOrder
SELECT Ay_Content.*, Ay_Class.bName AS bClassName, Ay_Class.bParent AS bParentID,
IIf(IsNull(c.bCommentCount),0,c.bCommentCount) AS bCommentCount
FROM Ay_Content a
LEFT JOIN Ay_Class b ON a.bClassID = b.bId
LEFT JOIN (select bArtID,count(*) as bCommentCount from Ay_Comment group by bArtID) c
ON a.bId = c.bArtID;
SELECT Ay_Content.*, Ay_Class.bName AS bClassName, Ay_Class.bParent AS bParentID, IsNull(c.bCommentCount,0) AS bCommentCount
FROM Ay_Content LEFT JOIN Ay_Class ON Ay_Content.bClassID = Ay_Class.bId
LEFT JOIN (select bArtID,count(*) as bCommentCount from Ay_Comment group by bArtID) AS c ON Ay_Content.bId = c.bArtID