语句如下:
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 的,这语句竟然不通用。如何写的呢?请指教一下,哪里出错了?
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 的,这语句竟然不通用。如何写的呢?请指教一下,哪里出错了?
解决方案 »
- (没分了)不过真心地请大家到这里,看一下常见的问题。因为我在网上找不到案,所以列上来,让大家帮忙一下!谢谢!在线!
- 员工表,包括员工姓名,员工出生年月等,如何汇总各年龄人数?
- 【SQL】如何检测数据库的数据变化?
- Rollback的异常处理
- 求sql语句,
- sql问题哈 50分求救
- SQL没有BOOLEAN类型的数据,怎么实现这样的要求呢?
- sql语句错误,请指教
- 请问如何在VC下对存储过程进行单步跟踪?
- 如何在存储过程中执行动态构造的查询语句?试过直接用sp_executeSql,可惜不行
- Help to add foreign key
- 数据库只有一个登录名字,怎样做论坛,多人同时操作,怎么处理?
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
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 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 * 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
--如果改为
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
ssp2009