Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
I want to display avg weight..based on last month sunday dates only...
C#
sno    name     weight     date     avgweight
1      aaa       100    06/07/2014     
1      aaa       200    13/07/2014     200(it's a 3 sunday's avg weight)
1      aaa       300    20/07/2014    


how to get average weight based on sunday...
how can i achive this..

please help me?
Posted
Updated 6-Aug-14 23:33pm
v3
Comments
Dilan Shaminda 7-Aug-14 5:55am    
have you tried anything so far? where did you stuck?

Hi,

Check this Link[^]. And look for Avg().


Hope this will help you.


Cheers
 
Share this answer
 
Comments
Magic Wonder 7-Aug-14 6:03am    
First you try yourself, if got stuck then you can be back with your query.
Hi, You can use something like the query below and improve it,

SQL
SET DATEFIRST 1;
select avg(weight) from your_table
group by DATEPART( dw, date)


The function
DATEPART( dw, date)
returns a number from 1 to 7 where 1 is Monday and 7 Sunday
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900