SQL statement that asks for two lines of time difference between different conditions in the same column
Table
CREATE TABLE ' Hp_report ' (
' id ' int (ten) unsigned not NULL auto_increment,
' Code ' varchar (255) is not NULL,
' Content ' Mediumtext not NULL,
' CTime ' datetime not NULL,
) Engine=myisam DEFAULT Charset=utf8 auto_increment=662555;
INSERT into ' Hp_report ' VALUES (2, ' a ', ' on ', ' 2014-07-04 21:17:53 ');
INSERT into ' Hp_report ' VALUES (3, ' A ', ' abc ', ' 2014-07-04 21:18:53 ');
INSERT into ' Hp_report ' VALUES (4, ' A ', ' off ', ' 2014-07-04 21:19:53 ');
INSERT into ' Hp_report ' VALUES (5, ' B ', ' on ', ' 2014-07-04 21:20:53 ');
INSERT into ' Hp_report ' VALUES (6, ' B ', ' abc ', ' 2014-07-04 21:22:53 ');
INSERT into ' Hp_report ' VALUES (7, ' B ', ' off ', ' 2014-07-04 21:29:53 ');
INSERT into ' Hp_report ' VALUES (8, ' a ', ' on ', ' 2014-07-04 21:34:53 ');
INSERT into ' Hp_report ' VALUES (9, ' a ', ' abc ', ' 2014-07-04 21:36:53 ');
INSERT into ' hp_report ' VALUES (' A ', ' off ', ' 2014-07-04 21:45:53 ');
INSERT into ' Hp_report ' VALUES (one, ' B ', ' on ', ' 2014-07-04 22:12:53 ');
INSERT into ' hp_report ' VALUES (' B ', ' abc ', ' 2014-07-04 22:18:53 ');
INSERT into ' hp_report ' VALUES (+, ' B ', ' off ', ' 2014-07-04 22:19:53 ');
I want to find out the difference between a and b,content for the ctime of off, and on, and sum the difference
That
INSERT into ' Hp_report ' VALUES (4, ' A ', ' off ', ' 2014-07-04 21:19:53 ');
And
INSERT into ' Hp_report ' VALUES (2, ' A ', ' on ', ' 2014-07-04 21:17:53 ');
difference between CTime (2 minutes)
INSERT into ' Hp_report ' VALUES (8, ' A ', ' on ', ' 2014-07-04 21:34:53 ');
INSERT into ' Hp_report ' VALUES ( ' A ', ' off ', ' 2014-07-04 21:45:53 ');
This is 11 minutes.
and add up all the difference in a.
The result I want is
A 13
b 16
Ask the great gods to help. Thank you!!
------Solution--------------------
Can we take the time out and calculate it later?
Strtotime ($row [' CTime ']);
Echo (Strtotime (' 2014-07-04 21:19:53 ')-strtotime (' 2014-07-04 21:17:53 '));
The result is 120 units of seconds
------Solution--------------------
Mysql> select * from Hp_report;
+----+------+---------+---------------------+
------Solution--------------------
Id
------Solution--------------------
Code
------Solution--------------------
Content
------Solution--------------------
CTime
------Solution--------------------
+----+------+---------+---------------------+
------Solution--------------------
2
------Solution--------------------
A
------Solution--------------------
On
------Solution--------------------
2014-07-04 21:17:53
------Solution--------------------
------Solution--------------------
3
------Solution--------------------
A
------Solution--------------------
Abc
------Solution--------------------
2014-07-04 21:18:53
------Solution--------------------
------Solution--------------------
4
------Solution--------------------
A
------Solution--------------------
Off
------Solution--------------------
2014-07-04 21:19:53
------Solution--------------------
------Solution--------------------
5
------Solution--------------------
B
------Solution--------------------
On
------Solution--------------------
2014-07-04 21:20:53
------Solution--------------------
------Solution--------------------
6
------Solution--------------------
B
------Solution--------------------
Abc
------Solution--------------------
2014-07-04 21:22:53
------Solution--------------------