• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic