-- CREATE TABLE STATEMENT create table log ( id int(11) not null auto_increment, event_id int(11) not null, num tinyint(1) not null, -- will be either 1 or -1 tstamp date not null, primary key (id), -- WHAT SHOULD MY INDEXES BE, CONSIDERING THE SELECT STATEMENT BELOW? ) engine = innodb ; -- TABLE DATA id | event_id | num | tstamp ---+----------+----------------- 1 | 1 | 1 | 2007-06-06 2 | 1 | 1 | 2007-06-06 3 | 1 | -1 | 2007-06-06 4 | 1 | 1 | 2007-06-06 5 | 1 | 1 | 2007-06-06 -- totals 3 for 2007-06-06 6 | 1 | 1 | 2007-06-07 7 | 1 | 1 | 2007-06-07 8 | 1 | 1 | 2007-06-07 9 | 1 | -1 | 2007-06-07 -- totals 2 for 2007-06-07 -- SELECT STATEMENT -- PRODUCES: 2007-06-06 | 3 2007-06-07 | 2 select tstamp as date, sum(num) as total_num from log where event_id=1 and (tstamp > current_date()-5) group by tstamp