When I am writing "Report Summary" type pages, one of the things I do is retrieve the data, but do some of the sorting in an array. One example might be for location counting
$store[$store_name][store_count]++;
And then foreach though them, or honestly I do one call to summarize the data, and then do a second call using DISTINCT to individual the data. SOrt of depend if you are in a resource scarce server environment
So an array is created for each store_name that is turning up results, and being autoincremented, so when I go through the display, I can just output
echo $store[$store_name][store_count];
Now, in some of the new versions of MYSQL some of this can be done using multiple selects, with counts involved, but using random hosting machines in the wild I have no idea what I am likely to run into, plus I don't do posgres
HERE IS MYSQL NOT POSGRESS version of what is might look like
SELECT
firstTable.id,
firstTable.store,
firstTable.list,
firstTable.regionNumber,
secondTable.id,
secondTable.store,
secondTable.location,
secondTable.regionNumber
FROM
firstTable
LEFT JOIN
secondTable
ON
first_Table.store = secondTable.store
AND
first_Table.regionNumber = secondTable.regionNumer
Good luck