gpt4 book ai didi

MySql 如何避免创建临时表

转载 作者:行者123 更新时间:2023-11-29 21:30:57 25 4
gpt4 key购买 nike

我对 SQL 非常陌生,需要通过 WordPress 插件 ( WP Data Tables ) 使用一个查询,但该插件不允许创建临时表。

要解决此问题,我相信我必须在联接中创建新表,但我不确定如何执行此操作。

我需要删除表创建的查询是:

create temporary table if not exists _SurveyData AS

(SELECT
_RefTable.RefID,
_RefTable.ClientRef,
_RefTable.SiteName,
_JobTable.JobID,
_JobTable.JobTypeID,
_JobTable.JobClosedDate
FROM
_RefTable, _JobTable
WHERE
_RefTable.RefID = _JobTable.RefID and _JobTable.JobTypeID = 1);

create temporary table if not exists _InstallData AS

(SELECT
_RefTable.RefID,
_RefTable.ClientRef,
_RefTable.SiteName,
_JobTable.JobID,
_JobTable.JobTypeID,
_JobTable.JobClosedDate
FROM
_RefTable, _JobTable
WHERE
_RefTable.RefID = _JobTable.RefID and _JobTable.JobTypeID = 2);

SELECT
_RefTable.RefID,
_RefTable.ClientRef,
_RefTable.SiteName,
_SurveyData.JobID,
_SurveyData.JobClosedDate,
_InstallData.JobID,
_InstallData.JobClosedDate
from
_RefTable, _SurveyData, _InstallData
Where
_RefTable.RefID = _SurveyData.RefID and _RefTable.RefID = _InstallData.RefID
order by RefID

任何帮助或正确方向的指出将不胜感激。

最佳答案

将临时表更改为子查询。

试试这个:

SELECT _RefTable.RefID,
_RefTable.ClientRef,
_RefTable.SiteName,
_SurveyData.JobID,
_SurveyData.JobClosedDate,
_InstallData.JobID,
_InstallData.JobClosedDate
from RefTable
INNER JOIN(
SELECT
_RefTable.RefID,
_RefTable.ClientRef,
_RefTable.SiteName,
_JobTable.JobID,
_JobTable.JobTypeID,
_JobTable.JobClosedDate
FROM RefTable, _JobTable WHERE _RefTable.RefID = _JobTable.RefID and _JobTable.JobTypeID = 1
) as _SurveyData on _RefTable.RefID = _SurveyData.RefID
INNER JOIN(
SELECT
_RefTable.RefID,
_RefTable.ClientRef,
_RefTable.SiteName,
_JobTable.JobID,
_JobTable.JobTypeID,
_JobTable.JobClosedDate
FROM _RefTable, _JobTable WHERE _RefTable.RefID = _JobTable.RefID and _JobTable.JobTypeID = 2
) as _InstallData on _RefTable.RefID = _InstallData.RefID
order by RefID;

关于MySql 如何避免创建临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35265483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com