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
Table of contents Preface 1. System Service Contr...
Table of contents 1. Preparation before installat...
Many people also asked me what books I read when ...
Business scenario: The visitor's visit status...
Table of contents 1. Introduction 2. Advantages 3...
The attributes of the <TD> tag are used to ...
1. Set firewall rules Example 1: Expose port 8080...
Table of contents Preface 1. Download MySQL from ...
Table of contents 1. jsonp cross-domain 2. docume...
Today, due to project requirements, js is needed t...
This article describes how to implement coexisten...
1. To develop web responsively, the page must ada...
A few days ago, I saw an example written by @Kyle...
1. Download and install VirtualBox software First...
Windows cmd telnet format: telnet ip port case: t...