All pastes #547132 Raw Edit

Anonymous

public sql v1 · immutable
·published 2007-06-07 08:44 UTC
rendered paste body
-- CREATE TABLE STATEMENTcreate 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 DATAid | 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, what are the totals for the last 5 days?-- CORRECTLY PRODUCES:  2007-06-06 | 3--                      2007-06-07 | 2select	tstamp as date,	sum(num) as total_numfrom	logwhere	event_id=1 and (tstamp > current_date()-5)group by	tstamp