Convergence a list of SQL statements of two lines of time difference formed by different conditions

Source: Internet
Author: User
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--------------------
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.