RSS Forums RSS
Please support our MS SQL advertiser: Programming Forums
Views: 628 | Replies: 0
Join Date: Jul 2007
Posts: 1
Reputation: cyberiatech is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cyberiatech cyberiatech is offline Offline
Newbie Poster

Question Help with odd Query

  #1  
Jul 23rd, 2007
I am trying to come up with a SQL query that will read timestamps from a table cross-referenced with the groups and individuals. What I want is results for each person on any given day with the first and last (min/max) EventTime. With the tables below, for example, an entry for Joe on 7/12/07 would need to be the first and last event on 7/12/07 within either of groups 1001 and 1003. Hopefully this makes sense.

If this is possible, and anyone could help out, I would greatly appreciate it!!!

Here's what the Events table looks like:

Id(PK) | EventTime | GroupId
===================================
1 | 1/22/2007 12:30pm | 1001
2 | 1/22/2007 2:30pm | 1001
3 | 1/23/2007 11:00am | 1002
4 | 1/23/2007 12:30pm | 1002
5 | 1/24/2007 11:00am | 1003
6 | 1/24/2007 12:30pm | 1003
7 | 1/24/2007 2:00pm | 1003


Here's what the Groups table looks like:

Id(PK) | Name
================
1001 | Accounting
1002 | HR
1003 | Sales
1004 | Marketing


Here's what the Individuals table looks like:

Id(PK) | Name | Primary | Secondary
===============================
2001 | Joe | 1003 | 1001
2002 | Bill | 1002 | 1003
2003 | Sam | 1001 | 1002
2004 | Jack | 1002 | 1003


What I need is output that would look something like this:

Date | StartTime | EndTime | Person
==================================
1/22/07 | 12:30pm | 2:30pm | Joe
1/22/07 | 12:30pm | 2:30pm | Sam
1/23/07 | 11:00am | 12:30pm | Bill
1/23/07 | 11:00am | 12:30pm | Jack
1/24/07 | 11:00am | 2:00pm | Joe
1/24/07 | 11:00am | 2:00pm | Bill
1/24/07 | 11:00am | 2:00pm | Jack
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:35 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC