1

このクエリをページネーションに使用しています

 SELECT * 
 FROM 
    (SELECT ROW_NUMBER() OVER (ORDER BY {0} {1}) AS RowNum, * 
     FROM Cars 
     WHERE IdOwner = {2}) AS Rows 
 WHERE RowNum > {3} AND RowNum < {4}

現在のように1つだけではなく、2つのテーブルでページネーションクエリを実行したいと思います。

SELECT * 
FROM 
    (SELECT ROW_NUMBER() OVER (ORDER BY {0} {1}) AS RowNum, 
            Cars.Id, Cars.Make, Cars.Model, Color.Name 
     FROM Cars 
     INNER JOIN Color ON Cars.ColorId = Color.Id 
     WHERE IdOwner = {2}) AS Rows 
WHERE RowNum > {3} AND RowNum < {4} 

私はIncorrect syntax near the keyword 'WHERE'.

問題が解決しました。みんなありがとう、私はそのような初心者です:(

SELECT * 
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY c.Id  ) AS RowNum, 
       c.Id, c.Make, c.Model, d.ColorName 
       FROM Car AS c 
       INNER JOIN Color AS d 
       ON c.ColorId = d.Id WHERE c.IdOwner=1 ) AS Rows
WHERE RowNum > 0 AND RowNum < 11 
4

2 に答える 2

4

ブラケットの問題である可能性があり、IdOwnerのプレフィックスを付ける必要があります。{0}と{1}パラメータのプレフィックスに注意してください:

SELECT ROW_NUMBER() OVER ( ORDER BY {0} {1} ) AS RowNum, 
       Cars.Id,Cars.Make, Cars.Model, Color.Name 
FROM (Cars INNER JOIN Color ON Cars.ColorId=Color.Id) 
WHERE Cars.IdOwner={2} 
于 2011-03-09T15:33:09.960 に答える
1

c.Makeが複数回指定され、「AS行」が削除されて必要になりました。

SELECT * 
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY c.Id  ) AS RowNum, 
       c.Id, c.Make, c.Model, d.ColorName 
       FROM Car AS c 
       INNER JOIN Color AS d 
       ON c.ColorId = d.Id WHERE c.IdOwner=1 ) AS Rows
WHERE RowNum > 0 AND RowNum < 11 
于 2011-03-09T16:58:49.060 に答える