1

SQL Server Compact EditionがRANK()関数をサポートしているようには見えません。( http://msdn.microsoft.com/en-us/library/ms174077(SQL.90).aspxのFunctions(SQL Server Compact Edition)を参照してください)。

SQL Server Compact EditionのSELECTステートメントでRANK()関数を複製するにはどうすればよいですか。

(SQL Server 2005 Management Studioで開くことができるのはNorthwind.sdfだけなので、サンプルのselectステートメントにはNorthwind.sdfを使用してください。)

4

2 に答える 2

1

使用する:

  SELECT x.[Product Name], x.[Unit Price], COUNT(y.[Unit Price]) AS Rank 
    FROM Products x
    JOIN Products y ON x.[Unit Price] < y.[Unit Price] 
                  OR (    x.[Unit Price]=y.[Unit Price] 
                      AND x.[Product Name] = y.[Product Name]) 
GROUP BY x.[Product Name], x.[Unit Price] 
ORDER BY x.[Unit Price] DESC, x.[Product Name] DESC;

以前:

SELECT y.id,
       (SELECT COUNT(*)
         FROM TABLE x
        WHERE x.id <= y.id) AS rank
  FROM TABLE y
于 2010-06-11T21:39:18.767 に答える
1
SELECT x.[Product Name], x.[Unit Price], COUNT(y.[Unit Price]) Rank 
FROM Products x, Products y 
WHERE x.[Unit Price] < y.[Unit Price] or (x.[Unit Price]=y.[Unit Price] and x.[Product Name] = y.[Product Name]) 
GROUP BY x.[Product Name], x.[Unit Price] 
ORDER BY x.[Unit Price] DESC, x.[Product Name] DESC;

学生のランクの検索-SqlCompactから変更されたソリューション学生のランク の検索-SqlCompact

于 2010-06-11T21:57:11.140 に答える