不知道如何GROUP_BY我的数据

时间:2018-07-03 00:10:13

标签: mysql sql

这是我的桌子的描述

async

我试图显示书名,写那本书的作者名单,书架号,总副本以及该书所在的图书馆。

await

我不知道如何以一种可以给我重复的标题/ isbn的方式对数据进行分组。

示例:一个图书馆有一本书,另一图书馆有同一本书,我想打印出每本书的数据。首先,它们都列在我的stored_on表中。当我不使用describe book; +----------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+-------------+------+-----+---------+-------+ | isbn | varchar(20) | NO | PRI | NULL | | | title | varchar(30) | YES | | NULL | | | date_published | date | YES | | NULL | | | publisher_id | int(11) | YES | | NULL | | +----------------+-------------+------+-----+---------+-------+ describe author; +------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+-------+ | author_id | int(11) | NO | PRI | NULL | | | first_name | varchar(20) | YES | | NULL | | | last_name | varchar(20) | YES | | NULL | | +------------+-------------+------+-----+---------+-------+ describe stored_on; +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | isbn | varchar(20) | YES | | NULL | | | total_copies | int(11) | YES | | NULL | | | shelf_number | int(11) | YES | | NULL | | | library | varchar(20) | YES | MUL | NULL | | +--------------+-------------+------+-----+---------+-------+ describe written_by; +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | isbn | varchar(20) | YES | MUL | NULL | | | author_id | int(11) | YES | MUL | NULL | | +-----------+-------------+------+-----+---------+-------+ 时,我可以打印出所有条目,但是在SELECT b.title, GROUP_CONCAT(CONCAT_WS(' ',a.first_name, a.last_name )) AS authors, so.shelf_number, so.total_copies, so.library FROM stored_on so LEFT OUTER JOIN book b ON so.isbn = b.isbn LEFT OUTER JOIN written_by wb ON wb.isbn = so.isbn LEFT OUTER JOIN author a ON wb.author_id = a.author_id GROUP BY (b.title); 字段中却得到了重复的条目。

似乎无法弄清楚这一点。

0 个答案:

没有答案