Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using query i get the below output as follows

Rate Bfid


1 72
2 72
3 72
4 72


From the above output i want the output as follows


Rate Bfid

2.5 72


adding the Rate values 1+2+3+4 = 10 divide bu number of 72's .

so in rate i get the 2.5


from using sql query how can i get the below output.

please help me.

Rgds,
Narasiman P.
Posted

1 solution

SQL
SELECT AVG(Rate), Bfid FROM tablename  GROUP BY Bfid


Edit: in case Rate is int, and not decimal, you will have to cast all values to decimal first, in order to be able to return decimal value. Like bellow:

SQL
CREATE TABLE #Test (Rate int, Bfid int)

INSERT INTO #Test (Rate, Bfid) VALUES (1, 72)
INSERT INTO #Test (Rate, Bfid) VALUES (2, 72)
INSERT INTO #Test (Rate, Bfid) VALUES (3, 72)
INSERT INTO #Test (Rate, Bfid) VALUES (4, 72)

SELECT AVG(CAST(Rate as decimal)), Bfid
FROM #Test
GROUP BY Bfid
ORDER BY Bfid

DROP TABLE #Test
 
Share this answer
 
v2

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