gpt4 book ai didi

mysql - SQL : Display all the records related to common id

转载 作者:行者123 更新时间:2023-11-30 23:01:08 24 4
gpt4 key购买 nike

我有下表

    id |         title
-------+--------------------
16 | Little Women
16 | The Tell-Tale Heart
16 | Practical PostgreSQL
16 | Dynamic Anatomy
18 | The Cat in the Hat
18 | Dune
20 | A Space Odyssey
20 | Goodnight Moon
41 | The Shining
41 | Programming Python
41 | Perl Cookbook

我希望输出如下所示:

    id |         title
-------+------------------
16 | Little Women
| The Tell-Tale Heart
| Practical PostgreSQL
| Dynamic Anatomy
18 | The Cat in the Hat
| Dune
20 | A Space Odyssey
| Goodnight Moon
41 | The Shining
| Programming Python
| Perl Cookbook

使用mysql在右栏中显示与id相关的所有记录。我怎样才能做到这一点?请为此提供解决方案,我将不胜感激。

最佳答案

试试这个

SELECT id,GROUP_CONCAT(title separator '\n') FROM mytable GROUP BY id

关于mysql - SQL : Display all the records related to common id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23908684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com