我想在同一查询中多次引用一个临时表。由于临时表的问题,我不能这样做:
http://dev.mysql.com/doc/refman/5.7/en/temporary-table-problems.html
因此,为了解决此问题,我正在创建临时表的重复项:
CREATE TEMPORARY TABLE IF NOT EXISTS earnings_temp_one AS (SELECT * FROM earnings WHERE earning_account_id = ?);
CREATE TEMPORARY TABLE IF NOT EXISTS earnings_temp_two AS (SELECT * FROM earnings WHERE earning_account_id = ?);
CREATE TEMPORARY TABLE IF NOT EXISTS earnings_temp_three AS (SELECT * FROM earnings WHERE earning_account_id = ?);
Run Code Online (Sandbox Code Playgroud)
但这要求我查询大量的表收入3次,这在一定程度上达不到目的。
我可以用其他名称复制临时表吗?
然后,我可以在海量表上运行查询一次。
也许有一个临时表问题的修复程序,不需要我创建重复项?
好的,我解决了:
CREATE TEMPORARY TABLE IF NOT EXISTS earnings_temp_one AS (SELECT * FROM earnings WHERE earning_account_id = ?);
CREATE TEMPORARY TABLE IF NOT EXISTS earnings_temp_two AS (SELECT * FROM earnings_temp_one);
CREATE TEMPORARY TABLE IF NOT EXISTS earnings_temp_three AS (SELECT * FROM earnings_temp_one);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2571 次 |
| 最近记录: |