mysql - get data from DB as range using php -


I have such a table_db

  id data value 1 2014-01-01 10 2 2014-01-02 10 3 / 2014-01-03 10 4/2014 Bar, 2014-01-04 Listened: 10 5, 2014-01-01, 20, 2014-01-01, 20, 7, 2014- 01-01, 30, 2014-01-01, / code>  

I have a SQL query that will give me this output

  from 2014-01-01 to 2014 -01-04 Price is from 2014 10- 01-05 to 2014-01-06 Price 20 to 2014-01-08 to 2014-01-08 Price is 30  

How do I Can i

For example ...

  being present in my table Drop Table on; Create table_m_table (id INT not outgraded primary key, date not DATE, zero, INT not zero); Enter my_table values ​​(1, '2014-01-01', 10), (2, '2014-01-02', 10), (3, '2014-01-03', 10), (4, '2014-01-04', 10), (5, '2014-01-05', 20), (6, '2014-01-06', 20), (7, '2014-01-07' , 10), (8, '2014-01-08', 10); SELECT a.date start, MIN (c.date) end, a_price my_table with one left left my_table b b.price = a.price and b.id = a.id - 1 right I = A.price and c.id & Gt; = A.id LEFT join my_table d on d.price = a.price and d.id = c.id + 1 where BID is zero and c.id is zero and not DID. Null group by a.id; + ------------ + ------------ + ------- + | Start | End Price | + ------------ + ------------ + ------- + | 2014-01-01 | 2014-01-04 | 10 | | 2014-01-05 | 2014-01-06 | 20 | | 2014-01-07 | 2014-01-08 | 10 | + ------------ + ------------ + ------- +  

Note that this Especially the solution assumes that the IDs are compatible.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -