gpt4 book ai didi

php - mysql-php,创建临时表时出错

转载 作者:行者123 更新时间:2023-11-29 06:51:03 26 4
gpt4 key购买 nike

我终于准备好将查询插入代码,但现在在运行整个查询时出现错误。我相信这与删除表功能有关。我最初让它们内联,然后读到我应该删除它并像这样在查询的开头添加:

    $query = $this->db->query("DROP TABLE IF EXISTS resultx;");
$query = $this->db->query("DROP TABLE IF EXISTS resulty;");

$query = $this->db->query("
CREATE TEMPORARY TABLE resultx AS
select *, CONCAT(Credit,'_',OrderStat) as consol from (..........

我正在创建两个临时表,然后在最后一个查询中加入它们。我不确定如何将第二个 DROP 临时表放回完整查询中,或者这是否是正确的方法。我得到的错误是:

A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use
near 'CREATE TEMPORARY TABLE resulty AS select packetDeet,Sales,SaleDate, UserID,Lead' at line 15

查询:

CREATE TEMPORARY TABLE resultx AS 
select
*,
CONCAT(Credit,'_',OrderStat) as consol
FROM
( select
packetDetailsId, GROUP_CONCAT(Credit) AS Credit,
GROUP_CONCAT(AccountNum) AS AccountNum,
GROUP_CONCAT(OrderStat) AS OrderStat
FROM
( SELECT
pd_extrafields.packetDetailsId,
CASE WHEN
pd_extrafields.ex_title LIKE ('%Credit%')
THEN pd_extrafields.ex_value
ELSE NULL
END as Credit,
CASE WHEN
pd_extrafields.ex_title LIKE ('%Account%')
THEN pd_extrafields.ex_value
ELSE NULL
END as AccountNum,
CASE WHEN
pd_extrafields.ex_title LIKE ('%Existing%')
THEN pd_extrafields.ex_value
ELSE NULL
END as OrderStat
FROM pd_extrafields
) AS myalias
GROUP BY packetDetailsId
)as TempTab;
CREATE TEMPORARY TABLE resulty AS select packetDeet,Sales,SaleDate, .........

请让我知道这是否有意义,或者我需要用更多信息更新问题。

最佳答案

如果您尝试在对 $this->db->query() 的一次调用中执行这两个查询,问题可能是您的数据库库不允许多个查询。

要查看这是否是问题所在,您应该将它们分成两个单独的查询。

关于php - mysql-php,创建临时表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15395041/

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