|
kj2398
Starting Member
2 Posts |
Posted - 2005-09-20 : 15:22:11
|
| Hopefully this will make sense:I am trying to write a query to return the last event posted for the latest cycle (for which we have data) for each system. I have 2 tables, cycle table and event table. For each cycle there are many events, cycle table contains multiple systems. Cycle and Event are linked by cycle_guid. Any help is appreciated. Sample DataCycle Table:Cycle Guid, Cycle_Date , ID System 1, 9/20/05, 18 2, 9/20/05, 19 3, 9/20/05, 20 4, 9/19/05, 18 5, 9/19/05, 19 6, 9/19/05, 20Event TableCycle GUID, Event ID, Event Time, 1, 146, Null 1, 147, Null 2, 146, 9/20/05 15:35 2, 147, 9/20/05 17:45 3, 146, 9/20/05 16:35 3, 147, Null 4, 146, 9/19/05 17:00 4, 147, 9/20/05 1:25 5, 146, 9/19/05 18:35 5, 147, 9/19/05 20:45 6, 146 9/19/05 15:00 6, 147 9/20/05 4:00 What I need returned is System ID, Latest Cycle ID, Latest Cycle Date, Latest Event ID, Latest Event Time 18, 5, 9/19/05, 147, 9/19/05 20:45 19, 2, 9/20/05, 147, 9/20/05 17:45 20, 6, 9/20/05, 146, 9/20/05 16:45I am currently doing a series of queries, one to get the last cycle date for each system, then one to get all the events for each system and then doing asp logic to loop thru the events and determine the latest event. While this does work, it is slow, and I think there should be a better way. Thanks, kj |
|