Skip to content
Advertisement

Average across rows in SQL Server 2008

I have the following table

In the YTD column I have to average the rows data. I can use average in columns but not sure how to average across rows.

Looking for the below results and using SQL Server 2008

Advertisement

Answer

I think cross apply is the simplest method:

Use case expressions, you can also express this as:

However, this formulation is messy and prone to typing errors.

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