Part of my query looks like this:
HAVING date > '2011-04-13 04:28:03'
The date variable is specified, does this affect the request?
EXPLAIN EXTENDED doesn't seem to use an index, but I don't know if it's just because I have 4 rows in the database I'm testing with.
My request:
SELECT AVG(slen) FROM ( SELECT date, COUNT(id) as slen FROM table WHERE product_id = 2830 GROUP BY id HAVING date > '2011-04-13 04:28:02' ) as T
There are several lines that have different date values. I want to select groups of identifiers that have a date> '2011-04-13 04:28:02'. Then I want the average number of rows to belong to the group, without a date condition .
The request as is, until it works.
My other problem was whether the date> '2011-04-13 04:28:02' would use the index of the date columns.
From this dataset:
sid datelast product_id 782240551706 2011-04-13 00:51:52 2830 782240551706 2011-04-13 04:05:48 2830 782240551706 2011-04-13 04:28:03 2830 111111111111 2011-04-13 00:50:30 2830
Desired Result:
The group with the identifier 782240551706 should be selected, and the average should be 3.
The following query gives the desired result:
SELECT AVG(slen) FROM ( SELECT date, COUNT(id) as slen FROM table WHERE product_id = 2830 GROUP BY id HAVING **max(date)** > '2011-04-13 04:28:02' ) as T
source share