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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.