获取最长日期-每笔交易 [英] Get Max Date - For Every Transaction

查看:67
本文介绍了获取最长日期-每笔交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

列之一是状态和日期 如果假设我想获取每个州的max(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

但是这里我的问题是我想为每笔交易获取max(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.

预先感谢

推荐答案

我将选择按创建日期排序的所有行:

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.

这篇关于获取最长日期-每笔交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆