且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取最长日期-每笔交易

更新时间:2023-02-12 22:16:19

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

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.