क्या दिनांक को group by
में जोड़ना उतना ही आसान है . यहां सिंटैक्स है जो MySQL और SQLite दोनों में काम करना चाहिए, समाप्ति समय पर तारीख को आधार बनाकर और समाप्ति समय को डेटाटाइम के रूप में संग्रहीत करना चाहिए:
SELECT ID, thedate, AVG(diff) AS average,
AVG(diff*diff) - AVG(diff)*AVG(diff) AS variance,
SQRT(AVG(diff*diff) - AVG(diff)*AVG(diff)) AS stdev,
MIN(diff) AS minTime,
MAX(diff) AS maxTime
FROM (SELECT t1.id, t1.endTimestamp, DATE(endtimestamp) as thedate,
min(t2.startTimeStamp) - t1.endTimestamp AS diff
FROM table1 t1 INNER JOIN
table1 t2
ON t2.ID = t1.ID AND t2.subject = t1.subject AND
t2.startTimestamp > t1.startTimestamp -- consider only later startTimestamps
WHERE t1.subject = 'entrance'
GROUP BY t1.id, t1.endTimestamp
) AS diffs
GROUP BY ID, thedate
यदि समय टिकट के रूप में संग्रहीत है, तो मार्टी की टिप्पणी देखें।