Where is the sentence inside over the sentence in postgres

Is it possible to use the where clause inside overclause as shown below?

SELECT SUM(amount) OVER(partition by prod_name WHERE dateval > dateval_13week)

I can’t use the previous and next inside over, because my dates are out of order. All I need to get are records whose values ​​are less than the 13-day date of the current record.

EDIT : 
sum(CASE WHEN dateval >= dateval_13week and dateval <=current_row_dateval then amount else 0 end) over (partition by prod_name order by week_end desc)

To clarify, I used to break records with the following query, when I had all my dates in sequence. Now I have the dates in random order, and there are some missing dates.

sum(amount) over 
        (partition by prod_name order by prod_name,week_end desc rows between 0 preceding and 12 following)
+4
source share
2 answers

You can model WHEREin the parameter SUM:

SELECT SUM(CASE WHEN dateval > dateval_13week THEN amount ELSE 0 END) 
           OVER(partition by prod_name)
+5
source

WHERE OVER. , , , CASE , .

0

Source: https://habr.com/ru/post/1529811/


All Articles