Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Challenging SQL

Status
Not open for further replies.

winaro

Programmer
Jul 13, 2007
1
EU

I have 2 tables

Table S
(S_rec_key decimal (15),
S_route varchar (50,0)
)
primary index (s_rec_key)

Table E
(E_rec_key decimal (15,0),
S_rec_key decimal(15,0),
E_stn varchar (3,0),
E_dtm timestamp
)

Table S contains information on the account and table E contains mutiple events for account. What I would like is that the field S.S_route in order of the E.E_dtm. Two events follwoing each other with the same E.E_stn are considered as one.

eg
S values (1,NULL)
S values (2, NULL)
E values (5,1,'BRU',TIMESTAMP '20070712 12:12:12')
E values (5,2,'AMS',TIMESTAMP '20070711 10:12:12')
E values (5,1,'BRU',TIMESTAMP '20070712 12:11:12')
E values (5,1,'FRA',TIMESTAMP '20070713 12:12:12')
E values (5,2,'CDG',TIMESTAMP '20070710 12:12:12')
E values (5,2,'HKG',TIMESTAMP '20070713 09:12:12')

I want a query that has as result that S looks like this:

1|'BRU,FRA'
2|'CGD,AMS,HKG'

Is this possible in pure sql?

Thanks

W
 
May be as simple as this. Did not check the syntax and may have misunderstood the question - the key element to eliminate 'duplicates' is the distinct DML statement.

select distinct e.e_stn
from e,
s
where e.e_s_rec_key
= s.s_rec_key
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top