Note that there are some explanatory texts on larger screens.

plurals
  1. POTSQL check if specific rows sequence exists
    primarykey
    data
    text
    <p>I have a table containing fields:</p> <pre><code>History_ID ORDER_ID Previous_STATUS_ID Next_STATUS_ID 0 2 null 1 1 2 1 2 2 2 2 3 3 1 null 1 4 2 3 4 5 3 null 2 6 2 4 1 7 2 1 2 8 2 2 5 9 7 3 4 </code></pre> <p>10 4 6 2 11 9 3 5</p> <p>It contains my order <code>ID</code> and <code>ID</code> of status. Basically table contains history of <code>STATUS</code> for every order.</p> <p>I would like to check if a specific order has a specific order sequence.</p> <p>Example: if order id 4 had states <code>2,4,3,1</code> then return true</p> <p>Statuses should be one after other so after 2 must be 4, after 4 is 3 and after that 1.</p> <p>Those sequences give me information (which will be displayed in my report) about flow of specific order.</p> <p>I need to check for that kind of sequences: </p> <ul> <li>1,2,3</li> <li>1,4,3,2</li> <li>4,2</li> <li>(1 or 2 or 3 or 4),5,3 - one of those 4 then 5 and then 3</li> </ul> <p>I don't have idea how to start with that kind of query :/</p> <p>EDIT:<br> My final report is a table containing information about orders like so:</p> <pre><code>Orders type Count ... Profile1 145 ... Profile2 217 ... Profile3 12 ... Profile4 2 ... </code></pre> <p>I have about 800k+ orders and my report must be done every day, so instead doing report for whole table (checking those STATES and aggregating informations from other tables) I have decided to create a report table:</p> <pre><code>Order_ID Profile Order_date Customer_profile ... 1 5 '2008-01-03' 2 4 1 '2009-04-10' 3 3 7 '2011-11-03' 1 4523 2 '2012-11-03' 5 </code></pre> <p>So that I can create a night job that will add new orders to this table with my information and I will just do a simple select from that table, to avoid aggregation. First insert will be big, but in next night it will only add new orders.</p> <p>For example look at order with ID = 2<br> Next_STATUS_ID ale like so: 1,2,3,4,1,2,5... I want to check if this order has history change like 1,2,5, so my function (select statement) should repeat 1 if it finds those ID's in that order.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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