Nikhil.Patel Nikhil.Patel - 1 year ago 90
SQL Question

Year wise Average days SQL

Today i have below problem while perform an sql query. Please find below data.

enter image description here

I perform SQL query on my table and get the below resulted output. i perform Group by on ID, Name, Week, Year, Days now i want the Days column as average of All Days based on year column. means there is multiple value of year is exist so i need Avg of Days data in all rows of DAYS for particular row. expected result as per below.

enter image description here

Thanks in Advance!!!
Write in comment if you have any query.

Answer Source

You can use OVER:

  AVG(Days) OVER (PARTITION BY LEFT(Year, 4)) AvgDays

Note: Just grouped by year (2016)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download