Get Max Date - For Every Transaction

杀马特。学长 韩版系。学妹 提交于 2020-03-25 17:57: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

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


回答1:


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.



来源:https://stackoverflow.com/questions/6910784/get-max-date-for-every-transaction

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!