本文介绍了SQL:显示所有与common id相关的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下表

    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

我希望输出应该如下所示:

I want the output should come like this shown below:

    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相关的记录.我怎样才能做到这一点?请为我提供解决方案,我将不胜感激.

Displaying all records that is related with id in the right column using mysql. How can I do this? Please provide me the solution for this I will be very grateful.

推荐答案

试试这个

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

这篇关于SQL:显示所有与common id相关的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 00:13