程序中的MYSQL Group Concat(MYSQL Group Concat in a Procedure)
mysql
我有一个像这样的表。表名=样本
id | product -------------- 1 | pen 1 | book 1 | eraser 2 | mouse 2 | keyboard我希望有这样的输出,
id | product ------------- 1 | pen,book,eraser 2 | mouse,keyboard通过使用group_concat获得输出。 但是,我需要通过一个程序获得相同的输出。 有人能帮我吗? 提前致谢。
I have a table like this below.table name=sample
id | product -------------- 1 | pen 1 | book 1 | eraser 2 | mouse 2 | keyboardI want to have an output like this,
id | product ------------- 1 | pen,book,eraser 2 | mouse,keyboardGot output by using group_concat. But, I need to have the same output through a procedure. Can someone help me? thanks in advance.
最满意答案
阅读完您的评论后,我认为您需要有关程序的帮助。
CREATE PROCEDURE `getdata`() BEGIN #Routine body goes here... select id,group_concat(`product` separator ',') as Result from mytbl group by id; END;你所要做的就是简单
call getdata();After reading your comments, i think you need help with procedure.
CREATE PROCEDURE `getdata`() BEGIN #Routine body goes here... select id,group_concat(`product` separator ',') as Result from mytbl group by id; END;All you have to do is simply
call getdata();更多推荐
发布评论