1

SQL Server Compact Edition 似乎不支持 RANK() 函数。(请参阅 http://msdn.microsoft.com/en-us/library/ms174077(SQL.90).aspx上的函数(SQL Server Compact Edition))。

如何在SQL Server Compact Edition SELECT 语句中复制 RANK() 函数。

(对于任何示例选择语句,请使用 Northwind.sdf,因为它是我可以使用 SQL Server 2005 Management Studio 打开的唯一一个。)

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;

解决方案从查找学生排名 -Sql Compact修改为 查找学生排名 -Sql Compact

于 2010-06-11T21:57:11.140 回答