Question : Group By Sql Query

Hello

I have written a SQL Query but need help with the group by


SELECT  distinct tblHFBYACC.Account, Avg(tblHFBYACC.Count) AS AvgCount
      ,(Datename(ww,getdate()) + '  ''' + Datename(yy,getdate()))as Period
 FROM tblHFBYACC  
      
 WHERE
      Datename(Year,getdate()) >= (Datename(Year,getdate()) + (DatePart(ww, getdate()) - 1) - 52)


Group By tblHFBYACC.Account,tblHFBYACC.Count
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Current OP:
AMP	3081	31  '2010
AMP	3084	31  '2010
AMP	3090	31  '2010
AMP	3092	31  '2010
AMP	3098	31  '2010
BCN	9	31  '2010
BCN	10	31  '2010
BHB	3169	31  '2010
BHB	3180	31  '2010
BHB	3184	31  '2010
BHB	3185	31  '2010
BHU	24	31  '2010
BHU	76	31  '2010
BHU	77	31  '2010


Required OP:

AMP	15445	31  '2010
BCN	19	31  '2010
BHB	12718	31  '2010
BHU	177	31  '2010

Answer : Group By Sql Query

you seem to want a SUM() and not AVG() also..?
1:
2:
3:
4:
5:
6:
7:
8:
SELECT  t.Account
      , AVG(t.Count) AS AvgCount
      , SUM(t.Count) AS SumCount
      ,(Datename(ww,getdate()) + '  ''' + Datename(yy,getdate())) as Period
 FROM tblHFBYACC t       
 WHERE Datename(Year,getdate()) >= (Datename(Year,getdate()) + (DatePart(ww, getdate()) - 1) - 52)
 GROUP BY  t.Account
Random Solutions  
 
programming4us programming4us