时间:2021-07-01 10:21:17 帮助过:3人阅读
存储过程版本:
BEGIN DECLARE Is_End INT DEFAULT 0; DECLARE _str VARCHAR(50) DEFAULT ‘‘; DECLARE _id INT; DECLARE _answer VARCHAR(50); DECLARE cur CURSOR FOR SELECT id,answer FROM question_library where id > 100 ORDER BY RAND() LIMIT 10; DECLARE CONTINUE HANDLER FOR NOT FOUND SET Is_End = 1; OPEN cur; FETCH cur INTO _id,_answer; WHILE Is_End != 1 DO SELECT CONCAT(_id,‘,‘,_str) INTO _str; FETCH cur INTO _id,_answer; END WHILE; CLOSE cur; SELECT left(_str,LENGTH(_str)-1) AS question; #去掉最后一个字符串“,” END
mysql 行转列(存储过程)
标签: