我尝试用图像做一个分页功能,当我这样做时效果很好:
WHERE tblUploadedImages.ImageID NOT IN (
SELECT TOP (@Exclude) ImageID FROM tblUploadedImages
ORDER BY tblUploadedImages.Added)
ORDER BY tblUploadedImages.Added
这样可行。但是,当我按喜欢这些图像的人数排序时,当我显示图像 11-20 时,某些图像不会被排除在外。
ALTER PROCEDURE GetMostLikedImages
@Exclude INT
AS
SELECT TOP (10)
(SELECT COUNT(DISTINCT UserID)
FROM tblLike
WHERE tblUploadedImages.ImageID = tblLike.ImageID) AS LikeCount,
(SELECT COUNT(ImageID)
FROM tblUploadedImages) AS ImageCount,
tblUploadedImages.ImgUrl,
tblUploadedImages.ImageID
FROM
tblUploadedImages
WHERE
tblUploadedImages.ImageID NOT IN
(SELECT TOP (@Exclude)
(SELECT COUNT(DISTINCT UserID)
FROM tblLike
WHERE tblUploadedImages.ImageID = tblLike.ImageID) AS LikeCount
ORDER BY LikeCount DESC, tblUploadedImages.Added)
ORDER BY
LikeCount DESC, tblUploadedImages.Added
LikeCount
如果我订购(有多少人喜欢这些图像),有人知道我怎么能使它工作