• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HQL: How to count green eye kittens?

 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi all
I would like to count the green eye kittens,
This HQL fetch query works fine:


but when i add the count(*)


I got this Exception (MSSQL):
Column 'cat.kittens' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.


What am I doing wrong?
Thank you!
 
Karsten Wutzke
Ranch Hand
Posts: 106
Hibernate MySQL Database Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
COUNT is an aggregate function. What column do you want to count the elements of?

You probably want to do:



Remember, COUNT, SUM, AVG, MIN, MAX are alle aggregate functions and always need a GROUP BY to do their operation on.

Karsten
 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Karsten

When running the query with the Group By clause this is the error I get:


I also tried
:

 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post us the entire SQL which was generated, so that we can take a look at it?
 
Sharon whipple
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once I removed the "fetch" keyword from the query it miraculously work...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic