这是我的table的描述
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);
我不知道如何将我的数据分组到最后,这样会给我重复的标题/isbn。
示例:一个图书馆有一本书,而另一个图书馆有同一本书,我想打印出每本书的数据。它们都列在我的存储表上,我可以打印出所有的条目时,我不使用 GROUP_CONCAT
,但我在 authors
现场。
我好像搞不懂这个。
暂无答案!
目前还没有任何答案,快来回答吧!