Just a question in passing:
I am writing a data extraction app for the travel industry. Given that a ticket from point A to point B might actually have several segments involved, I'd like to pull the data for the First segment only.
Heres a sample data set:
Recordkey SegmentNum SvcCat DepDate
blah 3 C 1-1-2000
blah 4 C 1-2-2000
blah 5 F 1-5-2000
You would think that whoever builds the database would automatically number the segments starting with 1. Unfortunately never the case. So in order to get the first ServiceCategory and DepartureDate, my SQL looks like this:
SELECT TS1.RECORDKEY, TS1.SEGMENTNUM, TS1.SVCCAT, TS1.DEPDATE
FROM SEGMENTS TS1,
(SELECT RECORDKEY, MIN(SEGMENTNUM)
FROM SEGMENTS GROUP BY RECORDKEY) TS2
WHERE TS1.RECORDKEY = TS2.RECORDKEY
This works, but I can't help thinking there must be some more efficient way to do this. Maybe some function that I'm unfamiliar with.
Anyhow, drop me a line here or at
cmorse at himark.com
Thanks in advance for any assistance.
I am writing a data extraction app for the travel industry. Given that a ticket from point A to point B might actually have several segments involved, I'd like to pull the data for the First segment only.
Heres a sample data set:
Recordkey SegmentNum SvcCat DepDate
blah 3 C 1-1-2000
blah 4 C 1-2-2000
blah 5 F 1-5-2000
You would think that whoever builds the database would automatically number the segments starting with 1. Unfortunately never the case. So in order to get the first ServiceCategory and DepartureDate, my SQL looks like this:
SELECT TS1.RECORDKEY, TS1.SEGMENTNUM, TS1.SVCCAT, TS1.DEPDATE
FROM SEGMENTS TS1,
(SELECT RECORDKEY, MIN(SEGMENTNUM)
FROM SEGMENTS GROUP BY RECORDKEY) TS2
WHERE TS1.RECORDKEY = TS2.RECORDKEY
This works, but I can't help thinking there must be some more efficient way to do this. Maybe some function that I'm unfamiliar with.
Anyhow, drop me a line here or at
cmorse at himark.com
Thanks in advance for any assistance.