] [ORDER BY ] [ROWS |...">

Window Function Over

The Over Clause documentation mentions "Rows" and "Range".

OVER (
      [PARTITION BY <expr>]
      [ORDER BY <expr>]
      [ROWS <expr> | RANGE <expr>]
     )

      

However, I could not find a detailed explanation regarding their functionality or any samples for using them. Can someone explain what these are and how they can be used?

+3


source to share


1 answer


Refer to the 'sprocket' request from fooobar.com/questions/965773 / ... :

ROWS and RANGE allow a window function to watch a window with user-defined rows, for example the previous 27 to run a moving average:



SELECT spend,
       SUM(spend) OVER (PARTITION BY user ORDER BY date ROWS BETWEEN 27 PRECEDING AND CURRENT ROW),
       user,
       date
FROM user_spend;

      

+3


source







All Articles