• Post Reply Bookmark Topic Watch Topic
  • New Topic

Count query

 
Darvesh Niz
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i can count how many cats are green for example like this
"select count(cat.name) from Cat cat group by cat.color"
and then i can say
List count = query.getResultList()
the result are plain numbers like 2,1 etc...

what is want is to fetch the color also
"select count(cat.color),color from Cat cat group by cat.color
this should get me a result
2 green
1 red

etc...

Any advice.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try it?

"select count(cat.color), cat.color from Cat cat group by cat.color"

or,

"select count(cat.id), cat.color from Cat cat group by cat.color"
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!