当前位置:网站首页>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
边栏推荐
- Go memory model for concurrency
- Several simple and difficult OJ problems with sequential force deduction
- Pyqt5 learning pit encounter and pit drainage (1) unable to open designer.exe
- Redux quick start
- EF Core: 一对一,多对多的配置
- Leetcode 763. partition labels divide alphabetic intervals (medium)
- Webrtc realizes simple audio and video call function
- Auto.js脚本开发环境搭建
- [C language] PTA 7-52 finding the sum of the first n terms of a simple interleaved sequence
- Recommendation system of online education
猜你喜欢

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

Classes and objects (II)

STL source code analysis (Hou Jie) notes -- Classification and testing of stl containers

Star a pathfinding in LAYA

GCC基础知识

Classes and objects (III)

Common current limiting methods

Use more flexible and convenient Rogowski coil

Idea small settings

Implementation of img responsive pictures (including the usage of srcset attribute and sizes attribute, and detailed explanation of device pixel ratio)
随机推荐
def fasterrcnn_ resnet50_ FPN () instance test
Classes and objects (II)
STL source code analysis (Hou Jie) notes -- Classification and testing of stl containers
[express connection to MySQL database]
Mongo shell interactive command window
学术 | [LaTex]超详细Texlive2022+Tex Studio下载安装配置
软件测试面试题(四)
un7.28:redis客户端常用命令。
UE 在场景或UMG中播放视频
Implementation of img responsive pictures (including the usage of srcset attribute and sizes attribute, and detailed explanation of device pixel ratio)
Actual combat of flutter - DIO of request encapsulation (II)
The most complete NLP Chinese and English stop words list in the whole station (including punctuation marks, which can be copied directly)
Redux quick start
Opencv environment construction
(heap sort) heap sort is super detailed, I don't believe you can't (C language code implementation)
I++ and ++i details
Review key points and data sorting of information metrology in the second semester of 2022 (teacher zhaorongying of Wuhan University)
Climbing the pit of traffic flow prediction (II): the simplest LSTM predicts traffic flow using tensorflow2
Detailed comparison of break and continue functions
Build auto.js script development environment