這裏是我的sql server 2008存儲過程。sql server 2008,不能使用子查詢中的順序
ALTER PROCEDURE [dbo].[GetSharedSmoothies]
@Page INT ,
@Status INT ,
@ItemPerPage INT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @X INT
DECLARE @Y INT
SET @X = (@Page - 1) * @ItemPerPage
SET @Y = @Page * @ItemPerPage
SELECT *
FROM (SELECT S.* ,
U.Avatar ,
U.Displayname ,
(SELECT COUNT(Id)
FROM Vote
WHERE Vote.SmoothieId = S.Id
) AS Votes ,
ROW_NUMBER() OVER (ORDER BY S.Id) rownum
FROM dbo.Smoothie AS S
INNER JOIN dbo.[User] AS U ON S.UserId = U.Id
WHERE S.IsPublic = 1
AND S.Status = 3
AND S.UserId > 0
-- ORDER BY S.CreatedDate DESC
) seq
WHERE seq.rownum BETWEEN @X AND @Y
ORDER BY seq.rownum
END
在我的代碼
,你會看到我的
-- ORDER BY S.CreatedDate DESC
註釋掉訂單,因爲訂單通過不會在子查詢工作。我需要展示最上面的一個。有沒有一種方法可以在我的代碼中使用順序?
+1添加
S.CreatedDate
格式化的代碼和非常清晰Ÿ措辭問題 –