??SQL Server???????
???????????? ???????[ 2014/5/5 9:53:54 ] ????????SQL Server ?????
????????????????е????? rownum????1??????????1?????????е??????1????????1????????Ρ? ???????????μ???????????и????rownum?в????????????where????У?????????????ROW_NUMBER()?????where?????????????????????÷???????????
SELECT ROW_NUMBER() OVER ( ORDER BY dbo.Products.ProductID DESC ) AS rownum ??
*
FROM dbo.Products
WHERE rownum BETWEEN 1 AND 10
?????????
Invalid column name 'rownum'.
SELECT ROW_NUMBER() OVER ( ORDER BY dbo.Products.ProductID DESC ) AS rownum ??
*
FROM dbo.Products
WHERE ( ROW_NUMBER() OVER (ORDER BY City) AS rown ) BETWEEN 1 AND 10
?????????
Incorrect syntax near the keyword 'AS'.
??????????????????????????????????????????????????????
SELECT *
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY dbo.Products.ProductID DESC ) AS rownum ??
*
FROM dbo.Products
) AS temp
WHERE temp.rownum BETWEEN 1 AND 10
?????????????????????????ROW_NUMBER????????????????????
SELECT *
FROM ( SELECT TOP ( @pageSize * @pageIndex )
ROW_NUMBER() OVER ( ORDER BY dbo.Products.UnitPrice DESC ) AS rownum ??
*
FROM dbo.Products
) AS temp
WHERE temp.rownum > ( @pageSize * ( @pageIndex - 1 ) )
ORDER BY temp.UnitPrice
???????????????????????????????????????????ROW_NUMER???????б??? ??????????????rownum??????????????ɡ?????????????
????????????????CTE???? (common_table_expression????????????????CTE????????? ?????ν??????????????????????????SQL??д??飬 ???)????ú???????????????CTE ???棬???£?
WITH ProductEntity
AS ( SELECT TOP ( @pageSize * @pageIndex )
ROW_NUMBER() OVER ( ORDER BY dbo.Products.UnitPrice DESC ) AS rownum ??
*
FROM dbo.Products
)
SELECT *
FROM ProductEntity
WHERE ProductEntity.rownum > ( @pageSize * ( @pageIndex - 1 ) )
ORDER BY ProductEntity.UnitPrice
??????????????????????????????Щ????£? ???CTE?????????????????и????Ч??????磬???????????CTE???洢?к????????????????Σ???????????????join????????£?
WITH ProductEntity
AS ( SELECT TOP ( @pageSize * @pageIndex )
ROW_NUMBER() OVER ( ORDER BY dbo.Products.UnitPrice DESC ) AS rownum ??
ProductID ??--??????
UnitPrice--?????????
FROM dbo.Products
)
SELECT *
FROM ProductEntity
INNER JOIN dbo.Products ON dbo.Products.ProductID = ProductEntity.ProductID
WHERE ProductEntity.rownum > ( @pageSize * ( @pageIndex - 1 ) )
ORDER BY ProductEntity.UnitPrice
???????ROW_NUMBER?????з?????????ú?????????? ?????????????LINQ?п???????TAKE ?? SKIP??????????????????????SQL???LINQ?????????????????????SQL???????????????????ROW_NUMBER???????????????????????????Console???????????????????LINQ To SQL??????÷?????????????£?
List<Product> product;
int pageSize = 10;
int pageIndex = 8;
using (ProductsDataContext context = new ProductsDataContext())
{
product = context.Products.OrderByDescending(x => x.UnitPrice)//????
.Skip(pageSize * (pageIndex-1))//??????????
.Take(pageSize)//?????????
.ToList();
}
????????????????????
???????????LINQ??????C#?????????????SQL????????SQLServer Profile ??????????????????????SQLServer??????
????Translate LINQ to SQL
??????????????俽???????????????
EXEC sp_executesql N'SELECT [t1].[ProductID]?? [t1].[ProductName]?? [t1].[SupplierID]?? [t1].[CategoryID]?? [t1].[QuantityPerUnit]?? [t1].[UnitPrice]?? [t1].[UnitsInStock]?? [t1].[UnitsOnOrder]?? [t1].[ReorderLevel]?? [t1].[Discontinued]
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY [t0].[UnitPrice] DESC) AS [ROW_NUMBER]?? [t0].[ProductID]?? [t0].[ProductName]?? [t0].[SupplierID]?? [t0].[CategoryID]?? [t0].[QuantityPerUnit]?? [t0].[UnitPrice]?? [t0].[UnitsInStock]?? [t0].[UnitsOnOrder]?? [t0].[ReorderLevel]?? [t0].[Discontinued]
FROM [dbo].[Products] AS [t0]
) AS [t1]
WHERE [t1].[ROW_NUMBER] BETWEEN @p0 + 1 AND @p0 + @p1
ORDER BY [t1].[ROW_NUMBER]'?? N'@p0 int??@p1 int'?? @p0 = 70?? @p1 = 10
??????????????????д?????ROW_NUMBER ???????????????????????SKIP??TAKE??LINQ????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11