15,961,678 members
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.

Rgds,
Narasiman P.
Posted

Solution 1

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```

v2

Top Experts
Last 24hrsThis month
 Rick York 40 OriginalGriff 30 Richard MacCutchan 15 Pete O'Hanlon 10 Patrice T 10
 OriginalGriff 178 Pete O'Hanlon 140 merano99 80 den2k88 50 Andre Oosthuizen 50

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