Note that there are some explanatory texts on larger screens.

plurals
  1. POCounting ordered data
    primarykey
    data
    text
    <p>I have the following problem to solve and I can't seem to be able to come up with an algorithm yet, nevermind an actual solution.</p> <p>I have a table of similar structure/data as the following, where IDs are not always in sequence for the same Ticker/QuouteType:</p> <pre><code>ID Ticker PriceDateTime QuoteType OpenPrice HighPrice LowPrice ClosePrice ------- ------ ---------------- --------- --------- --------- -------- ---------- 2036430 ^COMP 2012-02-10 20:50 95/Minute 2901.57 2905.04 2895.37 2901.71 2036429 ^COMP 2012-02-10 19:15 95/Minute 2909.63 2910.98 2899.95 2901.67 2036428 ^COMP 2012-02-10 17:40 95/Minute 2905.9 2910.27 2904.29 2909.64 2036427 ^COMP 2012-02-10 16:05 95/Minute 2902 2908.29 2895.1 2905.89 2036426 ^COMP 2012-02-09 21:00 95/Minute 2926.12 2928.01 2925.53 2927.21 </code></pre> <p>The information I need to extract from this data is the following: </p> <ul> <li>How many consecutive rows are there? Counting downwards from the most recent (as recorded in PriceDateTime), looking at ClosePrice?</li> </ul> <p>IE: For the current example the answer should be 2. ClosePrice (row 1) = 2901.71 which is greater than ClosePrice (row 2) = 2901.67 but lower than ClosePrice (row 3) = 2909.64. As such, looking back from the most recent price, we have 2 rows that "go in the same direction".</p> <p>Of course I have to do this across a lot of other names, so speed is quite important.</p> <p>PS: Thank you all for your help, I've drawn inspiration from all your answers when building the final procedure. You're all very kind!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload