Analysis of mysql temporary table usage [query results can be stored in temporary tables]

Analysis of mysql temporary table usage [query results can be stored in temporary tables]

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:
  • Detailed explanation of the difference between Mysql temporary table and partition table
  • Analysis of the principle and creation method of Mysql temporary table
  • How to use MySQL 5.7 temporary tablespace to avoid pitfalls
  • MySQL FAQ series: When to use temporary tables
  • In-depth analysis of JDBC and MySQL temporary tablespace
  • Simple usage of MySQL temporary tables
  • The difference between Update and select in MySQL for single and multiple tables, and views and temporary tables
  • Detailed explanation of the usage of two types of temporary tables in MySQL
  • A brief discussion on MySQL temporary tables and derived tables
  • Basic creation and use tutorial of temporary tables in MySQL
  • Some basic usage methods of temporary tables in MySQL
  • How to use temporary tables to speed up MySQL queries
  • Examples of using temporary tables in MySQL

<<:  How to reset Zabbix password (one-step)

>>:  Detailed explanation of the difference between Vue life cycle

Recommend

CentOS6.9+Mysql5.7.18 source code installation detailed tutorial

CentOS6.9+Mysql5.7.18 source code installation, t...

How to use physics engine joints in CocosCreator

Table of contents mousejoint mouse joint distance...

A brief analysis of the responsiveness principle and differences of Vue2.0/3.0

Preface Since vue3.0 was officially launched, man...

Detailed explanation of samba + OPENldap to build a file sharing server

Here I use samba (file sharing service) v4.9.1 + ...

Instructions for using the meta viewport tag (mobile browsing zoom control)

When OP opens a web page with the current firmwar...

5 basic skills of topic page design (Alibaba UED Shanmu)

This topic is an internal sharing in the second h...

Detailed explanation of the update command for software (library) under Linux

When installing packages on an Ubuntu server, you...

How to use the Marquee tag in XHTML code

In the forum, I saw netizen jeanjean20 mentioned h...

JavaScript Prototype Details

Table of contents 1. Overview 1.1 What is a proto...

How to upgrade https under Nginx

Purchase Certificate You can purchase it from Ali...

Vue Basics Listener Detailed Explanation

Table of contents What is a listener in vue Usage...

How to configure Nginx's anti-hotlinking

Experimental environment • A minimally installed ...

How to pass the value of the select drop-down box to the id to implement the code

The complete code is as follows : HTML code: Copy ...

HTML Basics - Simple Example of Setting Hyperlink Style

*** Example of setting the style of a hyperlink a...

Example code for implementing card waterfall layout with css3 column

This article introduces the sample code of CSS3 c...