1

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.

2
  • 2
    I removed the extraneous database tags. Feel free to add the one for the database you are really using. AVG() is supported as a window function by all databases (that I know of) that support window functions. Commented Nov 19, 2015 at 13:09
  • is this homework or do you have problems with some entity framework? Commented Nov 19, 2015 at 13:12

2 Answers 2

1

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

Is this answer an oversimplification of the problem at hand?

Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.