Hi Dave,
some modification of your original query should give the correct output, but the efficiency depends on the number of rows per name, it's fast if the number is low:
SELECT Contact_ALL.Name, Contact_ALL.DateTime,
COUNT(Contact_7.DateTime)
FROM Contact Contact_ALL
LEFT JOIN Contact AS Contact_7
ON Contact_ALL.Name= Contact_7.Name
AND Contact_7.DateTime < Contact_ALL.DateTime
AND Contact_7.DateTime >= Contact_ALL.DateTime - INTERVAL '7'DAY
GROUP BY 1,2
ORDER BY 1,2
Could you provide more details?
Average/maximum number of rows per user?
Do you need exact 7 days based on the timestamp or would it be enough to do it based on on a cast to date?
What is the range of dates within that table?
Dieter
Hi Dave,
some modification of your original query should give the correct output, but the efficiency depends on the number of rows per name, it's fast if the number is low:
Could you provide more details?
Average/maximum number of rows per user?
Do you need exact 7 days based on the timestamp or would it be enough to do it based on on a cast to date?
What is the range of dates within that table?
Dieter