开发者

Get Max Date - For Every Transaction

开发者 https://www.devze.com 2023-03-24 20:21 出处:网络
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

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

精彩评论

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

关注公众号