gunksta
May 6th, 2008, 02:46 AM
I need a helping hand from someone with more SQL experience than I. I am trying to write a couple of queries in OpenOffice.org Base and I've run into a problem.
I have two tables. Simplified, they look like this:
Sample
General_ID (this is a unique number)
Date_Selected
Event
General ID (this is not a unique number)
Date_Event
I have a sample population of people, each with a unique General_ID. Each row in table Event describes . . . . an event. Each member of the sample has at least one event. Most have more than one.
I need to learn about the events, relevant to the date the population was selected. Most of these event happen after the Date_Selected. I would like to make a query where I look at the first event, the second event, etc. for each ID number.
I know how to count how many events happened after the Date_Selected:
SELECT "Event"."General_ID", COUNT( "Event"."Date" )
FROM "Sample", "Event"
WHERE "Sample"."General_ID" = "Event"."General_ID" AND "Sample"."Date_Selected" <= "Event"."Date"
GROUP BY "Event"."General_ID"
This gives me something that looks like
General ID Number of Events
1 11
2 10
3 16
4 5
5 10
etc.
OK, so that tells me how many events happen to each member of my population, which is a good thing, but it's only part of what I need.
I'd like to be able to define a query to look at all of the first events, second events, etc. But, I don't know how. I appreciate any help on this. So, I'd like a query that returns something like:
General ID Date Stuff About My Event
1 1/1/08 Stuff
2 1/1/08 Stuff
3 1/1/07 Stuff
4 1/2/08 Stuff
5 1/3/08 Stuff
Such that I have a query that looks like this for ALL of the first event, second event, third event, etc. If I can figure out how to do this once, I'm sure I can apply the logic and make it work more than once.
Once I can write this query, I can compare the first set of events to the second set of events and so on, to measure for change in "Stuff".
P.S. - No, I can't reorganize the data, this is how we're pulling it out of the system. All I have are some nice big .csv files.
THANKS! THANKS! THANKS!
I have two tables. Simplified, they look like this:
Sample
General_ID (this is a unique number)
Date_Selected
Event
General ID (this is not a unique number)
Date_Event
I have a sample population of people, each with a unique General_ID. Each row in table Event describes . . . . an event. Each member of the sample has at least one event. Most have more than one.
I need to learn about the events, relevant to the date the population was selected. Most of these event happen after the Date_Selected. I would like to make a query where I look at the first event, the second event, etc. for each ID number.
I know how to count how many events happened after the Date_Selected:
SELECT "Event"."General_ID", COUNT( "Event"."Date" )
FROM "Sample", "Event"
WHERE "Sample"."General_ID" = "Event"."General_ID" AND "Sample"."Date_Selected" <= "Event"."Date"
GROUP BY "Event"."General_ID"
This gives me something that looks like
General ID Number of Events
1 11
2 10
3 16
4 5
5 10
etc.
OK, so that tells me how many events happen to each member of my population, which is a good thing, but it's only part of what I need.
I'd like to be able to define a query to look at all of the first events, second events, etc. But, I don't know how. I appreciate any help on this. So, I'd like a query that returns something like:
General ID Date Stuff About My Event
1 1/1/08 Stuff
2 1/1/08 Stuff
3 1/1/07 Stuff
4 1/2/08 Stuff
5 1/3/08 Stuff
Such that I have a query that looks like this for ALL of the first event, second event, third event, etc. If I can figure out how to do this once, I'm sure I can apply the logic and make it work more than once.
Once I can write this query, I can compare the first set of events to the second set of events and so on, to measure for change in "Stuff".
P.S. - No, I can't reorganize the data, this is how we're pulling it out of the system. All I have are some nice big .csv files.
THANKS! THANKS! THANKS!