程序中的MYSQL Group Concat(MYSQL Group Concat in a Procedure)

系统教程 行业动态 更新时间:2024-06-14 16:59:17
程序中的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 | keyboard

I want to have an output like this,

id | product ------------- 1 | pen,book,eraser 2 | mouse,keyboard

Got 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();

更多推荐

本文发布于:2023-04-16 14:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/4ac7a007b951515eeb246f5bcc99112a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   MYSQL   Group   Concat   Procedure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!