我不是一個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