简单问题:
有2个表:
流派[name,songID]
歌曲[id,title,userID,status]
SELECT id,name,title,userID,status FROM songs INNER JOIN genre ON song.id = genre.songID ORDER BY id ASC;
从
获取结果的查询是什么+----+-------------+----------------------+--------+--------+
| id | genre.name | song.title | userID | status |
+----+-------------+----------------------+--------+--------+
| 1 | tech | Feel it all | 1 | 1 |
| 2 | tech | Tester | 1 | 1 |
| 3 | music | Sejujurnya | 1 | 1 |
| 4 | music | Not Done | 1 | 1 |
| 5 | life | Cinta | 1 | 1 |
| 6 | life | Feel it all | 1 | 1 |
| 7 | life | Not Done | 1 | 1 |
| 8 | truth | Tester | 1 | 1 |
| 9 | tree | Tester | 1 | 1 |
| 10 | climb | Tester | 1 | 1 |
+----+-------------+----------------------+--------+--------+
到
+----+-------------+---------------------------------+--------+--------+
| id | genre.name | song.title | userID | status |
+----+-------------+---------------------------------+--------+--------+
| 1 | tech | Feel it all,Tester | 1 | 1 |
| 2 | music | Sejujurnya, Not Done | 1 | 1 |
| 3 | life | Cinta, Feel it all, Note Done | 1 | 1 |
| 4 | truth | Tester | 1 | 1 |
| 5 | tree | Tester | 1 | 1 |
| 6 | climb | Tester | 1 | 1 |
+----+-------------+---------------------------------+--------+--------+
由于
答案 0 :(得分:1)
将GROUP_CONCAT与GROUP BY
一起使用SELECT
id,
genre.name,
GROUP_CONCAT(title) as title,
userID,
status
FROM
songs
INNER JOIN
genre
ON
song.id=genre.songID
GROUP BY
genre.name
ORDER BY
id ASC
答案 1 :(得分:0)
SELECT
`Songs`.`id`,
`Genre`.`Name`,
GROUP_CONCAT(`Songs`.`Title`) as Title,
`Songs`.`userID`,
`Songs`.`status`
FROM
`Genre`,
`Songs`
WHERE
`Genre`.`SongID` = `Songs`.`id`
GROUP BY
`Genre`.`Name`