当前位置:网站首页>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
边栏推荐
- Simply change the picture color
- VScode 一键编译和调试
- Hengxing Ketong invites you to the 24th China expressway informatization conference and technical product exhibition in Hunan
- Mongo shell interactive command window
- Un7.28: common commands of redis client.
- Take you to understand JS array
- Recommendation system of online education
- JVM (heap and stack) memory allocation
- SGuard64.exe ACE-Guard Client EXE:造成磁盘经常读写,游戏卡顿,及解决方案
- [QT learning notes] * insert pictures in the window
猜你喜欢

Install the gym corresponding to mujoco in the spinning up tutorial, and the error mjpro150 is reported

Traffic flow prediction pit climbing record (I): traffic flow data set, original data

Reveal installation configuration debugging

ios面试准备 - 网络篇

如何避免示波器电流探头损坏

JVM (heap and stack) memory allocation

Use of construction methods

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

Classes and objects (I)

Post export data, return
随机推荐
Several simple and difficult OJ problems with sequential force deduction
def fasterrcnn_resnet50_fpn()实例测试
Introduction to auto.js script development
Tower of Hanoi classic recursion problem (C language implementation)
i++与++i详解
[QT learning notes] * insert pictures in the window
Leetcode (Sword finger offer) - 53 - I. find the number I in the sorted array
JVM (heap and stack) memory allocation
spinning up安装完使用教程测试是否成功,出现Library“GLU“ not found和‘from pyglet.gl import *错误解决办法
VScode 一键编译和调试
un7.28:redis客户端常用命令。
Oracle update and delete data
EF Core: 一对一,多对多的配置
Climbing the pit of traffic flow prediction (II): the simplest LSTM predicts traffic flow using tensorflow2
SGuard64.exe ACE-Guard Client EXE:造成磁盘经常读写,游戏卡顿,及解决方案
Classes and objects (III)
Software test interview questions (4)
Mujoco and mujoco_ Install libxcursor.so 1:NO such dictionary
File operation (Advanced C language)
Data Lake: spark, a distributed open source processing engine