
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- Using Time datatype in MySQL without seconds?
- How to query JSON datatype in MySQL?
- How to get the datatype of MySQL table columns?
- MySQL datatype to store month and year only?
- For timestamp, which datatype is used in MySQL?
- How to set NOW() as default value for datetime datatype in MySQL?
- Change a MySQL Column datatype from text to timestamp?
- How do I alter table column datatype on more than 1 column at a time in MySql?
- How to encrypt a CLOB datatype in JDBC?
- What is the best datatype for currencies in MySQL?
- Which datatype should I use for flag in MySQL?
- Which MySQL datatype to used to store an IP address?
- How to convert varchar “time” to real time in MySQL?
- What is the MySQL datatype to store DATALINK object in JDBC
- How to find datatype of all the fields in MongoDB?

Advertisements