sql server - How to select a specific set of rows and then select next row relevant to the original row -


I do not know whether I am possible with my current dataset, or if I'm hoping it is all possible.

What am I trying to do, get all the rows with the position = 2 or 7 and get the date and then the next line with the second position Get the duration of the date and the moment to get the pulse of those days.

Dataset
  id_compromiso | Fecha | Id_actividad | Status ------------ - + ----------- + ------------ + ---------- 32 2013-12-10 35 9 32 32 2013-12- 16 380 5 32 2013-12-18 401 7 32 2013-12-24 485 8 58 2013-12-02 248 2 58 2013-12-03 254 2 58 2013-12-10 360 2 58 2013-12-10 378 5 58 2013-12-12 395 2   

What have I tried:

SQL query: Act as Fchacha as act in the form of Pausa (SELECT tmp.id_compromiso, tmp.fecha, MIN (tact.id_actividad) Act as Act, Act (Act. Tus) = 7) as on TMP (tmp.id_compromiso = tact.id_compromiso and tmp.fecha = CAST (functioning as date.) Jah Efficiency. [Status] = tmp.id_compromiso, tmp.fecha) by the 7th group, amendment AS (SELECT tmp.id_compromiso, tmp.fecha, MIN (tact.id_actividad)) act as act as act Acting as action in the form of id_actividad act as fecha (act as act.) Act (ACT.ID_compromiso, Act). ] = 2) as on tmp (tmp.id_compromiso = tact.id_compromiso and tmp.fecha = CAST (methodology as the date.)) Where the strategy. [Status] = TMP.ID.comcompromiso, TMP by 2Group) SELECT * FROM revision by ORDER id_compromiso;

But actually I'm out of ideas how to get the next item with a different status from the table ...

< Div class = "post-text" itemprop = "text">

  - First of all, it increases activation so that the minimum fade for position on the agreement is included. This is the minimum (fade) in division by position / start with the agreement (select *, min (fade)) (actively position by id_compromiso, position) S-start), then join the extended activation table with yourself (Aliased A and B) agreement, but the situation is not 2,7 with the situation - it is 7 and (ASTT (2,7) and B. (2) section Not in) - - and make sure that this is a later condition (this A.sstart & lt; b.sStart bit) - At this point it also calculates the difference of position in the state of the day status_start_end AS (SELECT a. *, B.sStart sEnd, DATEDIFF (d, a .START, BSST ) From a SIDIF to a joint statusstat b on (aID- compromiso = BID-compromo and ATTS (2,7) and BSTs (2.7) and A from StateState. Start & LT; BSStart) - In the form of Finili, there will be difference of day in relation to all positions after the last Curie, Only need to select the minimum difference - the situation is really changing is we need to use separate duplicate; - As there may be several entries for the same situation - and very later the situation. In the status of the ID_compromiso, status, minute (SDIF) removed from status_start_and     (part by ID_Compromiso) status "

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -