2

我想添加一列(maxPrice),它将测量所有先前日期行的另一列(价格)的最大值。例如 - 表 1 有以下数据:

     Date       Price   
......................
    12/19/2008  5
    12/18/2008  7
    12/17/2008  5
    12/16/2008  3
    12/15/2008  4

希望输出为:

  Date     Price    MaxPrice
.................................
12/19/2008   5      7
12/18/2008   7      7
12/17/2008   5      5
12/16/2008   3      4
12/15/2008   4      4
4

1 回答 1

5
SELECT
`Date`, Price, (SELECT MAX(Price) FROM yourTable t2 WHERE t2.Date < t1.Date) AS MaxPrice
FROM
yourTable t1
于 2012-04-04T10:32:36.950 回答