它看起来并不像SQL Server Compact Edition中支持RANK()函数。 (参见功能(SQL Server精简版) http://msdn.microsoft.com/en-us/library/ms174077(SQL.90).aspx )。
我怎么会重复RANK()函数在SQL Server Compact Edition中的SELECT语句。
(请使用Northwind.sdf任何样本select语句,因为它是唯一一个我可以与SQL Server 2005 Management Studio中打开。)
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契约的发现排名修改的学生- SQL契约的发现排名
采用:
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
文章来源: How would I duplicate the Rank function in a Sql Server Compact Edition SELECT statement?