I am trying to use a SQL Server 2008 Ranking Function on a query sorted by a derived column. Here's an example

我试图在由派生列排序的查询上使用SQL Server 2008排名函数。这是一个例子

SELECT 
    table.FirstName, table.LastName, 
    CalculatedValue(table.number) As Points, 
    ROW_NUMBER() OVER (ORDER BY points) AS 'Row Number' 
FROM table 
ORDER BY points

I always get an error invalid column name "points" because the OVER function does not work with aliases, based on what I've read.

我总是得到一个错误无效的列名称“点”,因为根据我读过的内容,OVER函数不能使用别名。

Does anyone know an alternative where I can retrieve the sequential row number of a result set sorted by a derived column?

有没有人知道我可以检索由派生列排序的结果集的顺序行号的替代方法?

2 个解决方案

#1


3

How about using a derived table (sub query)? I think something like the following should work

如何使用派生表(子查询)?我认为以下内容应该有效

SELECT 
    ROW_NUMBER() OVER (ORDER BY sub.Points) AS 'Row Number',
    sub.FirstName,
    sub.LastName,
    sub.Points
FROM
(

    SELECT 
        table.FirstName, 
        table.LastName, 
        CalculatedValue(table.number) As Points
    FROM 
        table    
) sub
ORDER BY
    sub.Points

更多相关文章

  1. 查询表中的某一行,表中没有行号相关的属性字段,SQL语句怎么写啊?50
  2. 数据库截取字符串SUBSTR函数的使用
  3. SQL Server CLR函数类型不匹配。
  4. mysql中MAX()函数MIN()函数
  5. MySQL 中的函数(一:数学函数)
  6. SQL Server 2008使用sproc中的函数
  7. MYSQL存储过程,函数,光标
  8. 请问mysql中有没有类似math.max(1,2)这种可以比较两个值中最大值
  9. SQL 函数如何设置参数默认值

随机推荐

  1. Android SDK R14 发布
  2. 如何提高android代码质量
  3. android中的颜色值
  4. 在android中玩转wcf
  5. Android入门教程(九)之-----取得手机屏幕
  6. android 监听电源键
  7. android 监听webview的超链接点击
  8. Android获取应用程序信息——PackageMana
  9. 銆婄涓€琛屼唬鐮丄ndroid銆嬬瑪璁?/h1
  10. Android(安卓)ContentResolver CallLog