我有一个旧的帮助台票务系统,我的任务是将数据移出我们的新票务系统。这是我正在运行的查询:
DROP TABLE IF EXISTS final_table;
CREATE TABLE final_table (
name varchar(40),
ticketID BIGINT,
ticket_id BIGINT,
subject varchar(255),
priority_id varchar(10),
status varchar(10),
updated DATE,
created DATE,
closed DATE,
response LONGTEXT
);
ALTER TABLE final_table ADD PRIMARY KEY(ticket_id);
INSERT INTO final_table
SELECT name, ticketID, ticket_id, subject, priority_id, status, updated, created, closed, response
FROM ost_ticket;
ALTER TABLE final_table ADD response LONGTEXT;
ALTER TABLE final_table ADD impact varchar(40);
ALTER TABLE final_table ADD category varchar(20);
ALTER TABLE final_table ADD queue varchar (20);
UPDATE final_table SET impact = "1 person can't work";
UPDATE final_table SET category = "Other";
UPDATE final_table SET queue = "Help Desk";
INSERT INTO final_table( response )
SELECT GROUP_CONCAT(ost_ticket_response.response SEPARATOR "\n\n") AS response
FROM ost_ticket_response
GROUP BY ost_ticket_response.ticket_id;
旧的票务软件在ost_ticket_response表中多次列出PK,因此需要在最后四行中进行GROUP_CONCAT调用。基本上我正在尝试组合具有相同ticket_id的条目,然后将其拉入我正在创建的临时表中。如果我按现在运行查询,它只会使用null结果填充响应列。有什么想法吗?