Skip to content
Advertisement

Calculating the moving average in Vertica for all stocks

I have a stocks table for example:

I want to calculate moving average for all the stocks with a single query in Vertica.

This is the way to do so for only one stock (according to Vertica website):

Output:

If I try to select all the stock:

I am getting a wrong result.

How can I fix that?

Advertisement

Answer

Add a PARTITION BY clause to your call to AVG():

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement