0

I have this query :

SELECT * FROM public.app_catalog as a , (SELECT  app_id , COUNT(*) as count 
FROM public.statistics_log 
where logged_at between  '2019-08-20 12:22:40.186'   and '2019-08-22 12:22:40.186'           
GROUP BY app_id
LIMIT 10) AS App_id 
where App_id.app_id = a.app_catalog_id

And I want to write this in a Java repository

I tried like this:

/**
 * @param startDate .
  * @param enddate .
 * @return AppCatalog
 */
@Query("SELECT app FROM "
        + "(SELECT  b.app_id , COUNT(*) as count"
        + "FROM public.statistics_log as b inner join public.app_catalog as app on  b.app_id = app.app_catalog_id"
        + "where b.logged_at between :startDate and :endDate "
        + "GROUP BY b.app_id"
        + "LIMIT 10)app")
List<AppCatalog> findingTrendingAppsInCatalog(@Param("startDate") LocalDate startDate,
                                              @Param("endDate") LocalDateTime enddate);

The error I am getting:

Validation failed for query for method public abstract java.util.List com.xitee.cbc.repository.AppCatalogRepository.findingTrendingAppsInCatalog(java.time.LocalDate,java.time.LocalDateTime)!

But it seems the syntax is wrong because it does not compile.

1
  • It might help to include the error messages you get in your question. Commented Aug 22, 2019 at 11:57

1 Answer 1

2

You don't need the outer select and you need to leave spaces between the strings that you concatenate:

@Query("SELECT  b.app_id, COUNT(*) as count "
     + "FROM public.statistics_log as b inner join public.app_catalog as app "           
     + "ON b.app_id = app.app_catalog_id "
     + "WHERE b.logged_at BETWEEN :startDate and :endDate "
     + "GROUP BY b.app_id "
     + "LIMIT 10")
Sign up to request clarification or add additional context in comments.

7 Comments

Does this select all the column in app_catalog
It selects: app_id and count just like the query you wrote, because select * from (...) selected 2 columns.
I want to select all the column in app catalog, is that possible
This answer is about the syntax error you get. If you solved this and you have another requirement post a new question describing what you want.
Don't ask new questions in your question because you invalidate the existing answer(s).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.