Why doesn't LAST_VALUE return the last value?

前端 未结 3 463
盖世英雄少女心
盖世英雄少女心 2021-02-01 10:29

I want to find the last value of y over an ordered partition using a query like this:

SELECT
  x,
  LAST_VALUE(y) OVER (PARTITION BY x ORDER BY y AS         


        
3条回答
  •  猫巷女王i
    2021-02-01 10:51

    Even that question title uses LAST_VALUE - the question itself asks for Largest Value!
    I would just go with below:

    SELECT x, MAX(y) OVER (PARTITION BY x) FROM table  
    

    And if no other fields from table involved - i would just do simple GROUP BY:

    SELECT x, MAX(y) FROM table GROUP BY x 
    

    Of course, we shoudl remember that not always Largest value and MAX value are the same thing.

提交回复
热议问题