我想添加一个列(maxPrice),它将测量所有先前Date行的另一列(Price)的最大值。例如 - 表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
答案 0 :(得分:5)
SELECT
`Date`, Price, (SELECT MAX(Price) FROM yourTable t2 WHERE t2.Date < t1.Date) AS MaxPrice
FROM
yourTable t1