sql - math plus operator in query. summing up .select specified count variables -


i been trying add joins table shown in rails guide(e.g. publication_comments). call select on specified columns count, far it's working.

idea of plus reviews_count , pub_count = sum. faced problem how plus in query reviews_count , pub_count , order: "sum desc".

is possible make think? , how?

so far have code:

 @publication = publication.joins(:reviews, :publication_comments)                                   .select('"publications".*, count("reviews".id) reviews_count, count("publication_comments".id) pub_count')                                   .group('"publications".id')                                   .order("reviews_count desc") 

@publication = publication.joins(:reviews, :publication_comments)     .select('"publications".*, count("reviews".id) + count("publication_comments".id) my_count')     .group('"publications".id')     .order("my_count desc") 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -