对匹配行进行分组并添加新的空白行

发布于 2025-01-12 17:45:07 字数 1644 浏览 1 评论 0原文

我在 MYSQL 中有一个选择查询输出,如下所示:

Col 1Col2
FruitOrange
FruitApple
FruitBanana
VegetablePotato
VegetableOnion

我希望对第 1 列中的匹配行进行分组,如果它们这样做,我想将该列设为空白并创建一个新行,预期输出如下:

Col 1Col2
Fruit
Orange
Apple
Banana
Vegetable
Potato
Onion

有人可以帮我解决以下问题吗? 参考

I have a select query output in MYSQL as below:

Col 1Col2
FruitOrange
FruitApple
FruitBanana
VegetablePotato
VegetableOnion

And I am looking to group matching rows in column 1, and if they do, I want to make that column blank and create a new row, expected output as below:

Col 1Col2
Fruit
Orange
Apple
Banana
Vegetable
Potato
Onion

Can someone help me with below please?
Reference

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗酒趁年少 2025-01-19 17:45:07

我不确定你想做什么,但是你看过 mySQL 的 GROUP_CONCAT() 函数吗?

https://dev.mysql.com/ doc/refman/8.0/en/aggregate-functions.html#function_group-concat

I'm not sure what you want to do, but have you looked at the GROUP_CONCAT() function of mySQL?

https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文