- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to sum rows of VARCHAR datatype or TIME datatype in MySQL?
Let us first create a −
mysql> create table DemoTable1442 -> ( -> DueTime time -> ); Query OK, 0 rows affected (0.56 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1442 values('00:08:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1442 values('00:04:00'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1442 values('12:55:00'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select −
mysql> select * from DemoTable1442;
This will produce the following output −
+----------+ | DueTime | +----------+ | 00:08:00 | | 00:04:00 | | 12:55:00 | +----------+ 3 rows in set (0.00 sec)
Following is the query to sum rows of VARCHAR datatype or TIME datatype in MySQL −
mysql> select sec_to_time(sum(time_to_sec(DueTime) ) ) as TotalTime from DemoTable1442;
This will produce the following output −
+-----------+ | TotalTime | +-----------+ | 13:07:00 | +-----------+ 1 row in set (0.03 sec)
Advertisements