Fix for get_resources with postgresql

Add max_ts and min_ts to GROUP BY in sub-query, since they need to be aggregated to SELECT them.

Closes-Bug: #1241526
Change-Id: Ifdd2bc661b5da31bd40d1c3fa1fc442d7417399f