sql - How do I get the most recent database entry per ID, per day? -
i trying extract latest entry per id, per day database table, in database in sybase sql , language of report in query written oracle sql. i've tried modeling query after sql code posted elsewhere on site, extracts other date , time values besides max(). suspect reason of fields i'm using obtained conversion or string processing.
here query:
select substring(x.id, 1, datalength(x.id) - datalength(x.timeandaction)) 'identification', x.city, x.date, max (convert(varchar(15), x.utctime, 108)) 'maxtime' db_table x x.date >= 20140401 , x.date <= 20140403 , x.city in ('london', 'new_york', 'shanghai', 'tokyo') group x.id, x.city, x.date
(note: id contains location part of string)
the problem less recent times (i.e. unwanted data) being included in output of query. how can fix this?
the problem group based on id, field each value in database unique. correct result appeared when replaced
group x.id
with
group substring(x.id, 1, datalength(x.id) - datalength(x.timeandaction))
Comments
Post a Comment