mysql - Most efficient way to count how many rows have been entered in different tables within the X days? -
given several tables, best way take poll of row counts in tables clauses included? i'd @ once can inserted table daily record of row counts.
tablea - count of rows fit condition 1, specific column value x select count(*) tablea col1 = x
tablea - count of rows fit condition 2, specific column value y select count(*) tablea col2 = y
these 2 combined into:
select (select count(*) tablea col1 = x) 'x count', (select count(*) tablea col2 = y) 'y count'
but i'd add in: tableb - count of rows created within last specified interval
select count(*) tableb datecreated >= date_sub(curdate(), interval 1 day) col3 = z;
this gives me:
select (select count(*) tablea col1 = x) 'x count', (select count(*) tablea col2 = y) 'y count', (select count(*) tableb datecreated >= date_sub(curdate(), interval 1 day)) 'z count';
it seems run though, there more efficient way of counting rows in case?
your query looks fine, should index on columns. so, the documentation:
create index idx_col1 on tablea (col1); create index idx_col2 on tablea (col2); create index idx_datecreated on tableb (datecreated);
Comments
Post a Comment