Menu

1 / 6

Find the Longest Consecutive Rising Streak of a Single Stock

DEV Community: database·Judy·7 days ago
#JdlY2kD2
#devtodatabase#devto#dev#code#group
Long article (1152 words) — no AI summary yet.
Reading 0:00
15s threshold

Problem Description

The table stock records the daily closing prices of many stocks, with the fields CODE (stock code), DT (trading date) and CL (closing price). For a given stock (100046 in this example), find the number of days in its longest consecutive rising period. A consecutive rise here means the closing price does not fall back from one day to the next.

Source Data

The source table is large, so only part of the records are listed below:

Expected Result

Only one value, the maximum number of consecutive rising days: 4

On 01-02 the closing price rose from 3.89 to 3.93, a consecutive rise; on 01-05 it fell from 3.93 to 3.78, which breaks the rise, and a new rising run starts from there.

The longest run is 2009-01-07 to 2009-01-12: its starting point 01-07 closed at 3.77, below the 4.04 of 01-06, and then 4.02, 4.42 and 4.86 climbed steadily, four days without a fallback.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.