一条access 里的语句,麻烦帮我改写成 ms sqlserver 里面的语句

EexeNet 2011-02-21 07:05:01
语句如下:
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 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;


access 下的,麻烦帮我改写成ms sqlserver 的,这语句竟然不通用。如何写的呢?请指教一下,哪里出错了?
...全文
90 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
EexeNet 2011-02-21
  • 打赏
  • 举报
回复
很好,结贴,谢谢大家,特别感谢
ssp2009
zhuosh 2011-02-21
  • 打赏
  • 举报
回复
SQL code
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

快溜 2011-02-21
  • 打赏
  • 举报
回复

--如果改为
a.bParent = b.bId where a.bId=14 ) as aa
--你应该就懂了。
EexeNet 2011-02-21
  • 打赏
  • 举报
回复
ssp2009 你好,感谢你的答复,问一下,你的:a.bParent = b.bId where a.bId=14 ) aa

aa 是什么呢?
快溜 2011-02-21
  • 打赏
  • 举报
回复

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
快溜 2011-02-21
  • 打赏
  • 举报
回复
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
EexeNet 2011-02-21
  • 打赏
  • 举报
回复
access : 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

这句,又是哪错了,在sqlserver 提示 order 附近有错,

也需要改成 mssql里运行的
快溜 2011-02-21
  • 打赏
  • 举报
回复

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;
AcHerat 元老 2011-02-21
  • 打赏
  • 举报
回复

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

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧