【发布时间】:2023-03-29 14:29:01
【问题描述】:
我遇到了一个与 group_concat 相关的问题,因为当我使用它时,无法从基于 transactionID 的表中获取总记录 这是我的存储过程代码。在此,我使用了一个名为 strSplit 的拆分函数。
BEGIN
DECLARE iCount int;
DECLARE i int;
DECLARE txn VARCHAR(65000);
DECLARE txId VARCHAR(17);
CREATE TEMPORARY TABLE report_transaction (client_id INT NOT NULL AUTO_INCREMENT, productName VARCHAR(200), itxnId VARCHAR(100),PRIMARY KEY(client_id));
select count(distinct(tt.TxnId)) into iCount from tbl_transaction tt;
SELECT group_concat(distinct((tt.TxnId)) separator ', ') product into txn from tbl_transaction tt;
SET i=1;
WHILE i<iCount+1 DO
select strSplit(txn, ',', i) into txId;
SELECT RTRIM(LTRIM(txId));
INSERT INTO report_transaction(productName,itxnId) select group_concat((tt.ProductName) separator ',') products,tt.TxnId from tbl_transaction tt where tt.TxnId= txId;
SET i = i + 1;
END WHILE;
SELECT * FROM report_transaction;
drop table report_transaction;
END
我想要像表格记录一样的结果,但它只显示第一条记录,然后其他字段为空。
【问题讨论】:
标签: mysql group-concat