我不是一个mySQL向导,所以请原谅我,如果我犯了一个错误。但是,如果没有其他连接标准,它是整个表的话,我认为这可能为你工作:
select a.created as starttime
, b.created as endtime
, a.profit as startprofit
, b.profit as endprofit
, b.profit - a.profit as depth
from your_table a
join your_table b
on a.created < b.created
order by b.profit - a.profit
limit 1
如果有其他连接标准,期待与您的ID或赢家几个结果,或者通过别的东西加入,然后我会尝试如下所示。但是,不要忘记,您必须关联where子句中的子查询。所以,如果你是用id做的,你需要在子查询中使用where x.is = a.id
。
select a.created as starttime
, b.created as endtime
, a.profit as startprofit
, b.profit as endprofit
, b.profit - a.profit as depth
from your_table a
join your_table b
on a.created < b.created
...other join criteria...
where b.profit - a.profit = (select min(y.profit - x.profit)
from your_table x
join your_table y
on x.created < y.created
...other join criteria...
...where clause to correlate subquery...)
你如何定义“高”?你能举出一些示例数据并显示哪些数据点包含在Drawdown中? – RedFilter
我添加了一个链接到一个图像,显示一个线条图,应该更易于追踪。 – Dave