Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with column alias: Unknown column 'avg_rating' in 'where clause'

 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a basic sql statement as follows:



I have used a column alias for "avg(r.rating)" and named it "avg_rating".

It works in my Mysql Query browser without problem but when I run it from Java I get this:



Can anyone help please?

Thanks in advance,

Julien Martin.
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use 'as' between avg(r.rating) avg.rating
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Muhammad,
Thanks for the reply. However I still get the same exception after introducing the change: avg(r.rating) as avg_rating


any other idea?

Julien
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, looking at the errors, the where clause is unable to recognize the column.

replace the avg_rating >= 1 to avg(rt.rating).

You can't use the alias in "where" clause, the where clause must be provided with the column names already defined in database.

I hope this will work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic