SQL: retrieve only the records whose value has changed

后端 未结 7 1366
一整个雨季
一整个雨季 2020-12-17 02:13

Sorry for the nondescript title. I\'ll edit as we go along.

I have a table RateTable:

| Code   |  Date     |   Rate  |

  B001     2009-         


        
7条回答
  •  有刺的猬
    2020-12-17 02:27

    If I read this right, you aren't looking for modified rows, but rows where the rate changes from the previous date. This query or something like it should do it:

    SELECT  r1.Code, r1.Date, r1.Rate
    FROM    RateTable r1
    WHERE   r1.Rate <> (SELECT TOP 1 Rate
                       FROM    RateTable
                       WHERE   Date < r1.Date
                       ORDER BY Date DESC)
    

提交回复
热议问题