我写了一个mysql程序。我想使用不同的select语句进入临时表。在创建过程时,它会在'
附近显示语法错误SELECT
value as last
FROM
wp_13_rg_lead
LEFT JOIN wp_13_rg_' at line 18
以下是我的程序
DELIMITER $$
CREATE PROCEDURE TEMP_JOIN_WORK ()
BEGIN
start transaction;
CREATE TEMPORARY TABLE IF NOT EXISTS TEMP_JOIN(firstname varchar(500) not null,lastname varchar(500) not null) ;
insert into TEMP_JOIN(SELECT
value
FROM
wp_13_rg_lead
LEFT JOIN wp_13_rg_lead_detail on wp_13_rg_lead.id = wp_13_rg_lead_detail.lead_id
WHERE
wp_13_rg_lead.form_id = 9
AND CAST(wp_13_rg_lead_detail.field_number AS DECIMAL) = CAST(1.3 AS DECIMAL) ,
SELECT
value as lastname
FROM
wp_13_rg_lead
LEFT JOIN wp_13_rg_lead_detail on wp_13_rg_lead.id = wp_13_rg_lead_detail.lead_id
WHERE
wp_13_rg_lead.form_id = 9
AND CAST(wp_13_rg_lead_detail.field_number AS DECIMAL) = CAST(1.6 AS DECIMAL)
);
SELECT * FROM TEMP_JOIN;
commit;
END
$$
DELIMITER;
答案 0 :(得分:0)
这不应该给出语法错误。在工作台中,单击“创建存储过程”并在BEGIN END之间复制以下内容。逻辑是否有效,这是一个单独的问题。
CREATE TEMPORARY TABLE IF NOT EXISTS TEMP_JOIN(firstname VARCHAR(500) NOT NULL,lastname VARCHAR(500) NOT NULL) ;
INSERT INTO TEMP_JOIN VALUES((SELECT
`value`
FROM
wp_13_rg_lead
LEFT JOIN wp_13_rg_lead_detail ON wp_13_rg_lead.id = wp_13_rg_lead_detail.lead_id
WHERE
wp_13_rg_lead.form_id = 9
AND CAST(wp_13_rg_lead_detail.field_number AS DECIMAL) = CAST(1.3 AS DECIMAL)) , (
SELECT
`value` AS lastname
FROM
wp_13_rg_lead
LEFT JOIN wp_13_rg_lead_detail ON wp_13_rg_lead.id = wp_13_rg_lead_detail.lead_id
WHERE
wp_13_rg_lead.form_id = 9
AND CAST(wp_13_rg_lead_detail.field_number AS DECIMAL) = CAST(1.6 AS DECIMAL))
);
SELECT * FROM TEMP_JOIN;