Question is ... is the time stamp unique for each GISID and DATATYPE.
I doubt it ... so there most be something else destiguish which wone is the latest entry. Maybe the ID is populated from a sequence and the hightst id for a GISID, DATATYPE and TIME STAMP is the last entry ...
Then a solution would be
select tableX.GISID, tableX.DATATYPE, tableX.TIMESTAMP, tableX.ID, tableX.VALUE
FROM tableX
, (select GISID, DATATYPE, MAX(TIMESTAMP) TS, max(ID) I
FROM tableX
group by GISID, DATATYPE
) tabley
where tableX.GISID = tableX.GISID
, tableX.DATATYPE = tableY.DATATYPE
, tableX.TIMESTAMP = tableY.TS
, tableX.ID = tableY.I
If the timestamp is unique then simplify the quiry a little
select tableX.GISID, tableX.DATATYPE, tableX.TIMESTAMP, tableX.ID, tableX.VALUE
FROM tableX
, (select GISID, DATATYPE, MAX(TIMESTAMP) TS
FROM tableX
group by GISID, DATATYPE
) tabley
where tableX.GISID = tableX.GISID
, tableX.DATATYPE = tableY.DATATYPE
, tableX.TIMESTAMP = tableY.TS
Main Topics
Browse All Topics





by: orageniusPosted on 2004-08-04 at 03:34:20ID: 11713851
select * from tablex where ( GISID, DATATYPE, TIMESTAMP ) in
( select GISID, DATATYPE, max ( TIMESTAMP ) from tablex group by GISID, DATATYPE )
/