rashmi_k28 Posted March 5, 2008 Share Posted March 5, 2008 I have a values in database like this: 2008-03-05 12:20:01 | 0 | A| | 2008-03-05 12:20:01 | 1 | B | | 2008-03-05 12:30:02 | 1 | B | |2008-03-05 12:30:02 | 1 | A | | 2008-03-05 12:30:02 | 1 | B | | 2008-03-05 12:30:02 | 0 | C fields are timestamp,status and name. How to write a query when the status is changed from 0 to 1 I have to calculate the timestamp. Suppose if the status is 0 at 2008-03-05 12:20:01 and status has become 1 at 2008-03-05 12:30:01 how to find the information of status change in a day and calculate the duration Link to comment https://forums.phpfreaks.com/topic/94441-query/ Share on other sites More sharing options...
aschk Posted March 5, 2008 Share Posted March 5, 2008 So you want to find the time difference between 2 days essentially? Thus, have a look at SELECT TIMESTAMPDIFF(MINUTE, <field1>, <field2>) Apply it to your needs. I'm not going to do all the work for you Link to comment https://forums.phpfreaks.com/topic/94441-query/#findComment-483717 Share on other sites More sharing options...
rashmi_k28 Posted March 5, 2008 Author Share Posted March 5, 2008 The calculation of the field should be when the status is changed for the field `name` from 0 to 1 Link to comment https://forums.phpfreaks.com/topic/94441-query/#findComment-483785 Share on other sites More sharing options...
gin Posted March 6, 2008 Share Posted March 6, 2008 Use PHP (or whatever). When you change status, do a calculation right after. Link to comment https://forums.phpfreaks.com/topic/94441-query/#findComment-484570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.