当前位置:网站首页>MySQL time calculation function
MySQL time calculation function
2022-07-29 04:50:00 【Bitter and sweet】
example : Course schedule
The duration storage format of course learning records is minutes and seconds "01:02:33", Now it is necessary to make grouping statistics on the course learning and calculate the learning duration
Initialize table data
-- ----------------------------
-- Table structure for `course_study`
-- ----------------------------
DROP TABLE IF EXISTS `course_study`;
CREATE TABLE `course_study` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT ' Serial number ',
`course_id` varchar(48) CHARACTER SET utf8 DEFAULT NULL COMMENT ' Course number ',
`total_time` varchar(24) DEFAULT NULL COMMENT ' Cumulative learning time '
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=80 DEFAULT CHARSET=utf8mb4;
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (1, 'hguochen4779', '00:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (2, 'hguochen4780', '00:08:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (3, 'hguochen4781', '00:50:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (4, 'hguochen4785', '01:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (5, 'hguochen4786', '02:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (6, 'hguochen4822', '01:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (7, 'hguochen4823', '02:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (8, 'hguochen4824', '01:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (9, 'hguochen4825', '00:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (10, 'hguochen4826', '03:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (11, 'hguochen4832', '05:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (12, 'hguochen4833', '03:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (13, 'hguochen4838', '00:40:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (14, 'hguochen4839', '01:30:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (15, 'hguochen4840', '00:04:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (16, 'hguochen4841', '00:08:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (17, 'hguochen4845', '00:50:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (18, 'hguochen4867', '00:20:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (19, 'hguochen4868', '02:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (20, 'hguochen4869', '01:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (21, 'hguochen4870', '09:00:33.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (65, 'hguochen4962', '00:00:16.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (66, 'wk0001-1', '00:00:37.09');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (71, 'hguochen4962', '00:00:18.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (72, 'hguochen4976', '00:17:52.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (73, 'hguochen4980', '00:05:40.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (74, 'wk0001-1', '00:44:0.24');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (75, 'hguochen5026', '00:00:11.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (76, 'wk0001-1', '00:00:40.34');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (77, 'hguochen5067', '00:00:30.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (78, 'hguochen5113', '00:00:10.0');
INSERT INTO `course_study` (`id`, `course_id`, `total_time`) VALUES (79, 'hguochen5122', '00:00:58.0');
The process is as follows :
1> When parsing the original data 、 branch 、 second
2> Group statistics course , Sum and calculate the number 、 Duration ( Minutes and seconds )
3> Reconvert duration ( Minutes and seconds ) The format of
SELECT (SELECT name FROM course_info WHERE id = course_id) courseName,
course_num num,
CONCAT(hour_v + ((minute_v + (second_v DIV 60)) DIV 60),
':',
(minute_v + (second_v DIV 60)) MOD 60,
':',
second_v MOD 60) num1
FROM (SELECT course_id,
count(0) course_num, SUM(hour_v) hour_v,
SUM(minute_v) minute_v,
SUM(second_v) second_v
FROM (SELECT course_id,
HOUR(total_time) hour_v,
MINUTE(total_time) minute_v,
SECOND(total_time) second_v
FROM course_study) t
GROUP BY course_id) f
边栏推荐
- Makefile+make Basics
- def fasterrcnn_resnet50_fpn()实例测试
- IOS interview preparation - other articles
- Makefile+Make基础知识
- What are the core features of the digital transformation of state-owned construction enterprises?
- Mysql:The user specified as a definer (‘root‘@‘%‘) does not exist 的解决办法
- 新产品上市最全推广方案
- [c language] use the reverse order output of the linked list (bidirectional linked list)
- SSM integration, addition, deletion, modification and query
- 1 句代码,搞定 ASP.NET Core 绑定多个源到同一个类
猜你喜欢

There are objections and puzzles about joinpoint in afterreturning notice (I hope someone will leave a message)

使用更灵活、更方便的罗氏线圈

ios面试准备 - 网络篇
![Academic | [latex] super detailed texlive2022+tex studio download installation configuration](/img/4d/f8c60c0fbbd98c4da198cfac7989fa.png)
Academic | [latex] super detailed texlive2022+tex studio download installation configuration

Hengxing Ketong invites you to the 24th China expressway informatization conference and technical product exhibition in Hunan

Classes and objects (I)

Classes and objects (III)

常见的限流方式

(heap sort) heap sort is super detailed, I don't believe you can't (C language code implementation)

Command line interactive tools (latest version) inquirer practical tutorial
随机推荐
手机工作室网络如何组建?
2022杭电多校联赛第四场 题解
Various configurations when pulsar starts the client (client, producer, consumer)
让你的正则表达式可读性提高一百倍
[C language] PTA 7-52 finding the sum of the first n terms of a simple interleaved sequence
Leetcode 763. partition labels divide alphabetic intervals (medium)
Leetcode (Sword finger offer) - 53 - I. find the number I in the sorted array
Reveal安装配置调试
Install the gym corresponding to mujoco in the spinning up tutorial, and the error mjpro150 is reported
Un7.28: common commands of redis client.
Common rules of makefile (make) (II)
EF Core: 一对一,多对多的配置
Makefile+make Basics
Actual combat of flutter - DIO of request encapsulation (II)
数据湖:分布式开源处理引擎Spark
iOS面试准备 - 其他篇
Post export data, return
Dasctf2022.07 empowerment competition
On the use of pyscript (realizing office preview)
[QT learning notes] * insert pictures in the window