I want one mysql query please reply fast.....

Example :

CREATE TABLE history

(`User_ID` int, `startDate` date, `endDate` date, `Type` int)

;

INSERT INTO history

(`User_ID`, `startDate`, `endDate`, `Type`)

VALUES

(2, '2012-10-01', '2012-10-02', 0),


(2, '2012-10-03', '2012-10-04', 3),


(2, '2012-10-05', '2012-10-06', 3),


(2, '2012-10-05', '2012-10-06', 10),


(2, '2012-10-07', '2012-10-08', 1),


(2, '2012-10-07', '2012-10-08', 3),


(3, '2012-10-09', '2012-10-10', 6),


(3, '2012-10-09', '2012-10-10', <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />,


(3, '2012-10-11', '2012-10-12', 0),


(3, '2012-10-11', '2012-10-12', 1)

;

My Db this is

I want a query for the following answer

(`User_ID`, `startDate`, `endDate`, `Type`,pre_val)


(2, '2012-10-01', '2012-10-02', 0,NULL),


(2, '2012-10-03', '2012-10-04', 3,NULL),


(2, '2012-10-05', '2012-10-06', 10,3),


(2, '2012-10-07', '2012-10-08', 3,1),


(3, '2012-10-09', '2012-10-10', 8,6),


(3, '2012-10-11', '2012-10-12', 1,0)

based on date and user id please share if anyone knows the query

Check solution Here

Thank u for replying kostas

I want raw query don’t want yii cdb commands .plz if u know reply fast . :(

you do realise most of the people are volunteers nobody gets paid to answer questions. lol … reply fast