Skip to content
Advertisement

Complex SQL Query For Counting and Listing

I need to write complex sql for counting distinct names popularity and sorting them with descending order. I’ll do this with hibernate @Query(“SELECT * FROM …”) parameter. First I tried to do it on SQL then implement it to my spring boot project but I’m stuck while writing it.

Sorted version:

Advertisement

Answer

I think you are looking for group by. The query will look like this:

The jpql should be like this:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement