8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLのtime型の合計

Last updated at Posted at 2016-12-22

サンプルテーブル

  • テーブル定義
Column Type
time_onsite time
  • データ
time_onsite
00:00:01
00:01:00
01:00:00

time型を秒に変換

select
    time_onsite,
    time_to_sec(time_onsite) as sec
from
    time_table
;
time_onsite sec
00:00:01 1
00:01:00 60
01:00:00 3600

time型の合計

select
    sum( time_to_sec(time_onsite)) as total_sec,
    sec_to_time(sum( time_to_sec(time_onsite))) as total_time
from
    time_table
;
total_sec total_time
3661 01:01:01
8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?