# Why can't you do basic operations AFTER an aggregate in a window function? Like (max(x)+5), vs (5+max(x))

The syntax for aggregates and window functions is confusing, this does not work,

``````SELECT (max(x)+5) OVER ()
FROM generate_series(1,10) AS t(x);
``````

While this works

``````SELECT 5+max(x) OVER ()
FROM generate_series(1,10) AS t(x);
``````

That's fine if the operator is commutative, but I'm trying to divide an interval by seconds (in my specific case though I worked around it). Is there anyway to simplify this.

``````SELECT (max(x)/5) OVER ()
FROM generate_series(1,10) AS t(x);
``````

So another encapsulating query is not needed? Is this a PostgreSQL thing, or a SQL thing? Is there a way to disambiguate the query?

If I'm understanding your question correctly, you're trying to divide the result of the window function by 5. The entire window function consists of `MAX(x) OVER ()` therefore your query would look something like this:
``````SELECT MAX(x) OVER ()/5 FROM generate_series(1,10) AS t(x);
• purely for clarity, it can be useful to write this as `(MAX(x) OVER ())/5` – Jack Douglas Dec 16 '16 at 10:04
• or, `div(max() OVER (), 5)`. I just can't believe that's how SQL parses it. That's especially ugly. – Evan Carroll Dec 16 '16 at 20:48