当前位置:网站首页>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
边栏推荐
- Review key points and data sorting of information metrology in the second semester of 2022 (teacher zhaorongying of Wuhan University)
- [c language] PTA 7-50 output Fahrenheit Celsius temperature conversion table
- Opencv environment construction
- iOS面试准备 - 其他篇
- 1 句代码,搞定 ASP.NET Core 绑定多个源到同一个类
- Go面向并发的内存模型
- [express connection to MySQL database]
- [C] PTA 6-8 finding the height of binary tree
- Flink+iceberg environment construction and production problem handling
- Classes and objects (III)
猜你喜欢

GCC基础知识

五个关联分析,领略数据分析师一大重要必会处理技能

Implementation of flutter gesture monitoring and Sketchpad

Make a virtual human with zego avatar | virtual anchor live broadcast solution

让你的正则表达式可读性提高一百倍

EMI interference troubleshooting with near-field probe and current probe

Use jupyter (2) to establish shortcuts to open jupyter and common shortcut keys of jupyter

Post export data, return

Actual combat of flutter - DIO of request encapsulation (II)

MySQL - deep parsing of MySQL index data structure
随机推荐
Auto.js脚本开发入门
SGuard64.exe ACE-Guard Client EXE:造成磁盘经常读写,游戏卡顿,及解决方案
盒子水平垂直居中布局(总结)
Mujoco and mujoco_ Install libxcursor.so 1:NO such dictionary
Deep analysis of data storage in memory (Advanced C language)
STL source code analysis (Hou Jie) notes - STL overview
新产品上市最全推广方案
如何避免示波器电流探头损坏
ios面试准备 - 网络篇
Flutter 手势监听和画板实现
Mongo shell interactive command window
Flink+iceberg environment construction and production problem handling
五个关联分析,领略数据分析师一大重要必会处理技能
Software test interview questions (4)
Actual combat of flutter - DIO of request encapsulation (II)
Tower of Hanoi classic recursion problem (C language implementation)
IOS interview preparation - Objective-C
Makefile(make)常见规则(二)
Ethernet of network
央企建筑企业数字化转型核心特征是什么?