开发者

Get Max Date - For Every Transaction

in my table one of column is Status and Date if suppose i want to get max(date) for each state then i can use group by of date

But here my problem is i want to get max(date) for each transaction NOT FOR EACH STATUS

that means, my status values like ,create 开发者_运维问答/ modify / modify / submit / reject / modify / submit / reject / modify / submit now i want to get each transaction along with max date like

- create /(only one) modify / submit / reject / (again) modify /submit / reject / modify / Submit...

Can any one please suggest me to find solution for the above.

Thanks in advance

Joe


I would select all the rows sorted by create date:

SELECT status, created
FROM t      
WHERE  tid = 1 
ORDER BY created

Then filter (in the language of your choice) dropping any row that has a row after it of the same status.

However this will not quite work for you. Your data only contains a date column and as there are many status on a given date so there will be no order for a several statuses on a single day, you can solve this by storing the date/time created.

Depending on your database it may also be possible to produce the data using an analytic query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜