Click here to Skip to main content
15,888,022 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My query as follows


select distinct avg(r.rate) As Rate,f.bfid as BFid
FROM bthfac AS f,batch b,facfeedback r where f.facid= '60,75,6'
and f.Bthid=b.Bthid and r.bfid = f.bfid and b.class= 'PST'
and year(b.examdate)= '2011' and month(b.examdate)= '10' Group By r.Bfid

When i execute the above query shows error as follows


Column 'bthfac.BFid' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.


what is the problem in my above sql query.

please help me.

Regards,
Narasiman P.
Posted
Updated 17-May-13 23:40pm
v2

Basically, you are perfoming an average of all r.rate then in first place why you need BFid?

I think id its not required there and it should not be;

and also SQL will not allow it because its not consistent and cannot be achieved while you do Group by.

Therefore I would recommend you to understand what is Group by and how it works.

Some link for your reference: http://www.w3schools.com/sql/sql_groupby.asp[^]
 
Share this answer
 
When u use aggregate functions u have top use group by so u have to mention
SQL
r.Rate
also in Group By Clause
 
Share this answer
 
When you are grouping by some column(s) value, then you may select only those column(s) in the SELECT statement. You can not SELECT any column(s) those are not in GROUP BY clause. In you statement, you are grouping by r.Bfid, but, selecting f.bfid. This is not allowed. Just think it yourself why non GROUP BY column(s) are not allowed in SELECT statement.

I have changed the query. Check this.

SQL
select distinct avg(r.rate) As Rate, r.Bfid as BFid
FROM bthfac AS f,batch b,facfeedback r where f.facid= '60,75,6'
and f.Bthid=b.Bthid and r.bfid = f.bfid and b.class= 'PST'
and year(b.examdate)= '2011' and month(b.examdate)= '10' Group By r.Bfid
 
Share this answer
 

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