user2783069
user2783069

Reputation: 31

Window function implementation as a SQL query

How can I implement :

AVG(X) OVER(PARTITION BY SegmentId) AS AvgX

In a SQL query without using AVG(X)?

I can only support sum, count, min, max, but not AVG.

Thanks,

Or.

Upvotes: 1

Views: 119

Answers (2)

Fletch
Fletch

Reputation: 367

This returns the same results, although the context is unclear..

SUM(X) OVER(PARTITION BY SegmentId) / COUNT(X) OVER(PARTITION BY SegmentId)  AS AvgX

Upvotes: 1

LDMJoe
LDMJoe

Reputation: 1589

Conceptually, AVG(X) can be replaced by SUM(X) / COUNT(X)

Is this answer an oversimplification of the problem at hand?

Upvotes: 1

Related Questions