mysql - Loop or recursive sql query -


I have a table with numbers and dates (1 number is not required on each date and date at regular intervals). When there is no number in the table, I would like to get the number of dates

What I have (just an example, dates and "chiffers" are more complex):

 < Code> date | Chifera 2014-09-30 | 2 2014-09-29 | 1 2014-09-28 | 2 2014-09-27 | 2 2014-09-26 || 1 2014-09-25 | 2 2014-09-24 | 2  

etc ...

What do I need for the number "1":

  real_number_of_l_dates_batini_tw_g_gate_nets1 3  

Thanks to my actual query for Gordon Linoff,

  select the difference of numbers (NID) as D2 (choose dates from numbers where chiffre = 1 Date range according to date 2) d) Where dd.d1 between dd.d1 and dd.d2  

How can I test 3 with line 2? 4 with 4 etc ... not only the last 2? Should I use a loop without "border 2"? Or I can do without

If you type in 1

s, You should start with the next "1":
  select n *, (Choose date from Nums n2 where n2.chiffre = 1 and n2.date> n.date command according to date range 1) next_date to nums n where chiffre = 1;  

Then use it as a subquery to get what you want:

  Select n., Datediff (next_date, Select day from (as n *), select date (num) n2 where as n2.chiffre = 1 and n2.date & gt; ndate from order limit 1) next_date nums n where chiffre = 1) n;  

Comments