MSSQL内部联接与分页计数

时间:2019-02-12 23:25:35

标签: sql-server

我要加入2个表并返回需要COUNT的分页结果。

 SQLCount = "SELECT COUNT(Documents.ID) AS CatCount FROM Documents INNER JOIN Videos ON Videos.ID Where Documents.Active = '1' and Video.Active = '1' "
 Set rsCount = dbConnection.Execute(SQLCount)
 strCatCount = rsCount("CatCount")
 rsCount.Close
 Set rsCount = Nothing

 SQLCat = "SELECT * FROM Documents INNER JOIN Videos Where Documents.Active = '1' and Video.Active = '1' Order By " & strResultOrder
 Set rsCat = dbConnection.Execute(SQLCat)

这些都不起作用。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

可能缺少分组依据或加入条件:

SELECT d.Id as Id, COUNT(d.ID) AS CatCount
FROM Documents d
INNER JOIN Videos v ON v.ID = d.Id
WHERE d.Active = '1' 
GROUP BY d.Id;