This article uses an example to illustrate the usage of MySQL temporary tables. Share with you for your reference, the details are as follows: 1. Create a temporary table to store query results . It can be used in the query sql for report making. (1) Regarding the storage method, MySQL does not support: select * into tmp from maintenanceprocess (2) You can use: create table tmp (select ...) Example: #Single station maintenance result table upper part drop table if EXISTS tmp_Single station maintenance result table (inspection report) upper part; create table tmp_ single workstation maintenance result table (inspection report) upper part (select workAreaName as 'machine number', m.jobNumber as 'maintenance personnel number', u.userName as 'maintenance personnel name', loginTime as 'maintenance start time', CONCAT(FLOOR((TIME_TO_SEC(exitTime) - TIME_TO_SEC(loginTime))/60),'minutes') as 'Maintenance duration' from maintenanceprocess as m LEFT JOIN user u ON m.jobNumber = u.jobNumber where m.jobNumber = [$maintenance personnel number] and loginTime = [$maintenance start time] );#Create a temporary table select * from tmp_single station maintenance result table (inspection report) upper part; Note: [$Maintenance start time] is a value that can be entered for query (3) Another example of creating a temporary table: In the stored procedure: BEGIN #Routine body goes here... declare cnt int default 0; declare i int default 0; set cnt = func_get_splitStringTotal(f_string,f_delimiter); DROP TABLE IF EXISTS `tmp_split`; create temporary table `tmp_split` (`val_` varchar(128) not null) DEFAULT CHARSET=utf8; while i < cnt do set i = i + 1; insert into tmp_split(`val_`) values (func_splitString(f_string,f_delimiter,i)); end while; END Readers who are interested in more MySQL-related content can check out the following topics on this site: "MySQL query skills", "MySQL common functions summary", "MySQL log operation skills", "MySQL transaction operation skills summary", "MySQL stored procedure skills" and "MySQL database lock related skills summary" I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
<<: How to reset Zabbix password (one-step)
>>: Detailed explanation of the difference between Vue life cycle
CentOS6.9+Mysql5.7.18 source code installation, t...
Table of contents mousejoint mouse joint distance...
Preface Since vue3.0 was officially launched, man...
Here I use samba (file sharing service) v4.9.1 + ...
When OP opens a web page with the current firmwar...
This topic is an internal sharing in the second h...
When installing packages on an Ubuntu server, you...
In the forum, I saw netizen jeanjean20 mentioned h...
Table of contents 1. Overview 1.1 What is a proto...
Purchase Certificate You can purchase it from Ali...
Table of contents What is a listener in vue Usage...
Experimental environment • A minimally installed ...
The complete code is as follows : HTML code: Copy ...
*** Example of setting the style of a hyperlink a...
This article introduces the sample code of CSS3 c...