I need to be able to tell the date of when a sum is met or exceeded. For example:
I would like to know the date for when sum(minutes) >= 400 for each personid
I've been trying something like this without success
Code:
session(sessionid, personid, date, minutes) sessionid is PK, personid is FK, there will be multiple records for each personid
I've been trying something like this without success
Code:
SELECT min(a.dated), a.personid, thesum FROM ( SELECT sum(t1.minutes) as thesum, t2.dated, t2.personid FROM session t1 INNER JOIN session t2 ON t1.personid = t2.personid AND t1.dated <= t2. GROUP BY t2.dated, t2.personid HAVING thesum >= 400 ) a group by a.dated, a.personid
Comment