Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use temporary tables in mysql

Shulou Source: shulou.com Published: 2022-05-31 22:46:53 09月30日 Update

This article will explain in detail how to use temporary tables in mysql. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Create a temporary table to store the query results

(1) mysql does not support the storage method:

Select * into tmp from maintenanceprocess

(2) you can use:

Create table tmp (select...)

For example:

# Top of single station maintenance result table drop table if EXISTS tmp_ single station maintenance result table (inspection report) Create table tmp_ single station 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 ((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 temporary table select * from tmp_ upper part of single station maintenance result table (inspection report)

Note: [$maintenance start time] is a value that can be entered for query

(3) an example of another way to create a temporary table:

In a stored procedure:

BEGIN#Routine body goes here...declare cnt int default 0 leading i int default 0 political set cnt = func_get_splitStringTotal; DROP TABLE IF EXISTS `tmp_ split`; create temporary table `tmp_ split` (`val_ `varchar) DEFAULT CHARSET=utf8;while I < cntdoset I = I + 1 × insert into tmp_split (`val_ `) values (func_splitString); end while END on how to use temporary tables in mysql to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Results individual station personnel report time inspection content article method more knowledge article query good remarks name duration machine quality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia Shulou Technology MariaDB Shulou Tech Info