fix statistics query in postgres

when aggregate functions present, postgres requires all
non-aggregate columns selected to be included in group by clause
to ensure a single value is selected.

Change-Id: Iccbcd8046cca872e8eba472f48fa392114f34426
Closes-Bug: #1256318
(cherry picked from commit 551bbbb0dff43d22d7cca7826af1b3ef5868168b)
Merge "fix statistics query in postgres" into stable/icehouse