I got a very basic query which gets a top 10 of searched words:
select distinct keyword, sum (amount) as keyword_amount from search group by keyword order by keyword_amount DESC
This works fine in PostGresAdmin 4, I get a top 10. But when I want to test it on Spring via Postman on a endpoint, it keeps giving me 500 errors. It says ID is not found and/or should be in the group by or used in an aggregate function. I found in other topics I need to use 'distinct' or put ID in min/max(?). Still no success, and it's weirder that it does work in PostGreSQL itself.
I tried:
@Query( value = "select distinct keyword, sum (amount) as keyword_amount from search " +
"group by keyword order by keyword_amount DESC",
nativeQuery = true
)
List<Search> findTop10Keywords();
which give me the missing ID errors, and I tried without nativeQuery, but then I get:
search is not mapped [select distinct keyword, sum (amount) as keyword_amount from search group by keyword order by keyword_amount DESC
I'm not sure why/where search must be mapped?