I have this query to print 10 product with each category
WITH MyRowSet AS (SELECT *,
ROW_NUMBER() OVER (PARTITION BY p.cateID ORDER BY p.cateID DESC)
AS RowNum
FROM Product p )
SELECT TOP 100 * FROM MyRowSet WHERE RowNum <= 10
Then I want to get the next 100 products with OFFSET / FETCH. How I can do this?
You need to use an order by
clause to specify which rows to fetch and which to offset:
WITH MyRowSet AS (SELECT *,
ROW_NUMBER() OVER (PARTITION BY p.cateID ORDER BY p.cateID DESC)
AS RowNum
FROM Product p )
SELECT *
FROM MyRowSet
WHERE RowNum <= 10
ORDER BY p.cateId, rownum
OFFSET 100 ROWS FETCH NEXT 100 ROWS ONLY;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.