代码之家  ›  专栏  ›  技术社区  ›  AMissico

如何在SQL Server Compact Edition Select语句中复制rank函数?

  •  1
  • AMissico  · 技术社区  · 16 年前

    看起来SQL Server Compact版本不支持rank()函数。(见 函数(SQL Server Compact Edition) 在 http://msdn.microsoft.com/en-us/library/ms174077(SQL.90).aspx )

    如何在 查询性能优化 选择语句。

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

    2 回复  |  直到 16 年前
        1
  •  1
  •   Community Mohan Dere    9 年前
    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 在 Finding rank of the student -Sql Compact

        2
  •  1
  •   OMG Ponies    16 年前

    用途:

      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