473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Select date that a sum()'s threshold is met

I need to be able to tell the date of when a sum is met or exceeded. For example:
Expand|Select|Wrap|Line Numbers
  1. session(sessionid, personid, date, minutes)
  2. sessionid is PK, personid is FK, there will be multiple records for each personid
  3.  
I would like to know the date for when sum(minutes) >= 400 for each personid

I've been trying something like this without success
Expand|Select|Wrap|Line Numbers
  1. SELECT min(a.dated), a.personid, thesum FROM (
  2.  
  3. SELECT sum(t1.minutes) as thesum, t2.dated, t2.personid
  4. FROM session t1
  5. INNER JOIN session t2 ON t1.personid = t2.personid
  6. AND t1.dated <= t2.
  7. GROUP BY t2.dated, t2.personid
  8. HAVING thesum >= 400
  9. ) a 
  10.  
  11. group by a.dated, a.personid
  12.  
May 5 '10 #1

✓ answered by jkmyoung

having sum(t1.minutes) >= 400

it's kind of stupid that you aren't able to alias it.

2 1924
jkmyoung
2,057 Expert 2GB
having sum(t1.minutes) >= 400

it's kind of stupid that you aren't able to alias it.
May 5 '10 #2
Thank you for your fast reply. Your tip helped me. I had to make one other change:

GROUP BY t2.sessionid, t2.personid

GROUP BY a.personid

because each person may have multiple entries for the same day.

Thank you so much for your advice, this site has been very useful to me for several years
May 5 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Syl | last post by:
Hi group - I have a table with a date field: eventdate date I need to select all records where the eventdate is 7 days from today. Any ideas ? I've been looking at diffdate but I don't...
9
by: Thomas R. Hummel | last post by:
Hello, I am importing data that lists rates for particular coverages for a particular period of time. Unfortunately, the data source isn't very clean. I've come up with some rules that I think...
2
by: Agnes | last post by:
I want to select the date into the date form (yy-Mm-dd) e.g 05-Mar-16 and then make it as string
5
by: tkba | last post by:
Hi All, Please help me to understand if I can add calendar to a date field in forms which will allow users to enter the date. Regards, TK
3
by: wish | last post by:
Dear all; Can someone guide me how to code out the javascript to calculate the estimate date based on the user selected date and the how long the duration in term of week. eg. 19/9/2007 is...
1
by: thupham | last post by:
In winform, we help Date time Picker control, then we can select only 1 value, but I want to select many value in a month. I don't know other tool or con trol to add to my project for that purpose....
11
by: jglabas | last post by:
I have a MS Access query that calculates a member’s attendance at team events over the past 12-months (i.e., Now()-365). This is one of several queries used; others calculate the total number of...
2
by: shannonwhitty | last post by:
I am able to extract dates in the correct format i.e. SELECT CONVERT(VARCHAR(8), GETDATE(), 3) =dd/mm/yy My issue is that my users are selecting a date in this format and I need to select...
1
by: pavanip | last post by:
Hi, I am having database table as TicketNo,Name,Issue Date. I inserted the data for "IssueDate" field using calender control in Asp.Net. So the table data looks like this TicketNo ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.