Calculate average per row in SQL Server
<p>I need to calculate the average per day from 1 st record of year for each row.
I can do it by iterating in a while loop but am sure that I can achieve this simpler. I woould nee a query to calculate the avgAmount near the Amount field. </p>

<p>The average is simply calculated by summing the amounts and divide by the difference between min and max dates for each row.</p>

<pre><code>create table a
(
date  datetime,
dept varchar(50),
amount float
)

insert into a values ('2016-02-07', 'abc', 25)
insert into a values ('2016-02-27', 'abc', 20)
insert into a values ('2016-03-09', 'abc', 30)
insert into a values ('2016-03-28', 'abc', 45)
insert into a values ('2016-04-07', 'abc', 40)
insert into a values ('2016-04-30', 'abc', 50)
insert into a values ('2016-05-07', 'abc', 60)
insert into a values ('2016-05-27', 'abc', 50)
insert into a values ('2016-06-30', 'abc', 38)
insert into a values ('2016-07-17', 'abc', 45)
insert into a values ('2016-07-30', 'abc', 55)
insert into a values ('2016-08-07', 'abc', 70)
</code></pre>

<p><a href="http://sqlfiddle.com/#!3/592a3/7" rel="nofollow">SQLFIDDLE</a></p>

<p>Any help please?</p>