Say I have a table with the columns
category_id, sub_category_id, time.
I want to be able to do various aggregate queries like
SELECT COUNT(*) FROM table WHERE category_id IN (1, 2) AND sub_category_id IN (3, 4) GROUP BY category_id, subcategory_id, DATE_PART('day', time - '2000-01-01 00:00:00'::timestamp).
What would be the best way to store and retrieve data so that such queries are efficient?