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

A detailed introduction to Linux system configuration (service control)

Table of contents Preface 1. System Service Contr...

Complete steps to install MySQL 5.5 on CentOS

Table of contents 1. Preparation before installat...

Recommend some useful learning materials for newbies in web design

Many people also asked me what books I read when ...

How to check if data exists before inserting in mysql

Business scenario: The visitor's visit status...

Detailed explanation of Vuex overall case

Table of contents 1. Introduction 2. Advantages 3...

HTML table tag tutorial (26): cell tag

The attributes of the <TD> tag are used to ...

Detailed explanation of firewall rule settings and commands (whitelist settings)

1. Set firewall rules Example 1: Expose port 8080...

MySQL 8.0.23 installation super detailed tutorial

Table of contents Preface 1. Download MySQL from ...

Eight implementation solutions for cross-domain js front-end

Table of contents 1. jsonp cross-domain 2. docume...

Summary of WEBAPP development skills (notes for mobile website development)

1. To develop web responsively, the page must ada...

Method to detect whether ip and port are connectable

Windows cmd telnet format: telnet ip port case: t...