清理mysql中的数据
我有一个非常大的数据集,它被破坏得有点太远了,我需要把它拉回来 例如,假设数据是DVD盒集。最初的编目员将每一集作为一个条目添加(但按季进行了标识)。但是,我们只关心盒装DVD中的单个DVD 我想编写一个查询,根据ID号将这些条目分组,并将标题添加到blob字段中 那就是 给定一个如下所示的记录集清理mysql中的数据,mysql,Mysql,我有一个非常大的数据集,它被破坏得有点太远了,我需要把它拉回来 例如,假设数据是DVD盒集。最初的编目员将每一集作为一个条目添加(但按季进行了标识)。但是,我们只关心盒装DVD中的单个DVD 我想编写一个查询,根据ID号将这些条目分组,并将标题添加到blob字段中 那就是 给定一个如下所示的记录集 | ID | Title +-----------+------------------------------------------------------------ | 1234
| ID | Title
+-----------+------------------------------------------------------------
| 1234 | Batman: Season 1, Episode 6: "Batman Is Riled" |
| 1234 | Batman: Season 1, Episode 7: "Instant Freeze" |
| 5678 | Batman: Season 2, Episode 9: "The Greastest Mother of Them All" |
| 5678 | Batman: Season 2, Episode 7: "The Spell of Tut" |
| 5678 | Batman: Season 2, Episode 6: "Barbecued Batman?" |
| 5678 | Batman: Season 2, Episode 3: "Hot Off the Griddle" |
| 9012 | Batman: Season 3, Episode 24: "The Joker's Flying Saucer" |
| 9012 | Batman: Season 3, Episode 25: "The Entracing Dr. Cassandra" |
| 9012 | Batman: Season 3, Episode 26: "Minerva, Mayhem and Millionaires"
我想把它转换成一个新的结构,比如
| ID | Title | Description
| 1234 | Batman |Batman: Season 1, Episode 6: "Batman Is Riled"; Batman: Season 1, Episode 7: "Instant Freeze" |
| 5678 | Batman |Batman: Season 2, Episode 9: "The Greastest Mother of Them; Batman: Season 2, Episode 7: "The Spell of Tut"; Batman: Season 2, Episode 6: "Barbecued Batman?"; Batman: Season 2, Episode 3: "Hot Off the Griddle" |
| 9012 | Batman |Batman: Season 3, Episode 24: "The Joker's Flying Saucer"; Batman: Season 3, Episode 25: "The Entracing Dr. Cassandra"; Batman: Season 3, Episode 26: "Minerva, Mayhem and Millionaires"
这在mysql中是可能的,还是我需要把它放到电子表格中 就行了
MySQL 5.6架构设置:
CREATE TABLE dvd
(`ID` int, `Title` varchar(64))
;
INSERT INTO dvd
(`ID`, `Title`)
VALUES
(1234, 'Batman: Season 1, Episode 6: "Batman Is Riled"'),
(1234, 'Batman: Season 1, Episode 7: "Instant Freeze"'),
(5678, 'Batman: Season 2, Episode 9: "The Greastest Mother of Them All"'),
(5678, 'Batman: Season 2, Episode 7: "The Spell of Tut"'),
(5678, 'Batman: Season 2, Episode 6: "Barbecued Batman?"'),
(5678, 'Batman: Season 2, Episode 3: "Hot Off the Griddle"'),
(9012, 'Batman: Season 3, Episode 24: "The Joker''s Flying Saucer"'),
(9012, 'Batman: Season 3, Episode 25: "The Entracing Dr. Cassandra"'),
(9012, 'Batman: Season 3, Episode 26: "Minerva, Mayhem and Millionaires"')
;
select id, substring(title,1,locate(":",title)-1) title,
group_concat(title SEPARATOR ";") as description
from dvd
group by ID
| ID | title | description |
|------|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1234 | Batman | Batman: Season 1, Episode 6: "Batman Is Riled";Batman: Season 1, Episode 7: "Instant Freeze" |
| 5678 | Batman | Batman: Season 2, Episode 9: "The Greastest Mother of Them All";Batman: Season 2, Episode 7: "The Spell of Tut";Batman: Season 2, Episode 6: "Barbecued Batman?";Batman: Season 2, Episode 3: "Hot Off the Griddle" |
| 9012 | Batman | Batman: Season 3, Episode 24: "The Joker's Flying Saucer";Batman: Season 3, Episode 25: "The Entracing Dr. Cassandra";Batman: Season 3, Episode 26: "Minerva, Mayhem and Millionaires" |
查询1:
CREATE TABLE dvd
(`ID` int, `Title` varchar(64))
;
INSERT INTO dvd
(`ID`, `Title`)
VALUES
(1234, 'Batman: Season 1, Episode 6: "Batman Is Riled"'),
(1234, 'Batman: Season 1, Episode 7: "Instant Freeze"'),
(5678, 'Batman: Season 2, Episode 9: "The Greastest Mother of Them All"'),
(5678, 'Batman: Season 2, Episode 7: "The Spell of Tut"'),
(5678, 'Batman: Season 2, Episode 6: "Barbecued Batman?"'),
(5678, 'Batman: Season 2, Episode 3: "Hot Off the Griddle"'),
(9012, 'Batman: Season 3, Episode 24: "The Joker''s Flying Saucer"'),
(9012, 'Batman: Season 3, Episode 25: "The Entracing Dr. Cassandra"'),
(9012, 'Batman: Season 3, Episode 26: "Minerva, Mayhem and Millionaires"')
;
select id, substring(title,1,locate(":",title)-1) title,
group_concat(title SEPARATOR ";") as description
from dvd
group by ID
| ID | title | description |
|------|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1234 | Batman | Batman: Season 1, Episode 6: "Batman Is Riled";Batman: Season 1, Episode 7: "Instant Freeze" |
| 5678 | Batman | Batman: Season 2, Episode 9: "The Greastest Mother of Them All";Batman: Season 2, Episode 7: "The Spell of Tut";Batman: Season 2, Episode 6: "Barbecued Batman?";Batman: Season 2, Episode 3: "Hot Off the Griddle" |
| 9012 | Batman | Batman: Season 3, Episode 24: "The Joker's Flying Saucer";Batman: Season 3, Episode 25: "The Entracing Dr. Cassandra";Batman: Season 3, Episode 26: "Minerva, Mayhem and Millionaires" |
:
CREATE TABLE dvd
(`ID` int, `Title` varchar(64))
;
INSERT INTO dvd
(`ID`, `Title`)
VALUES
(1234, 'Batman: Season 1, Episode 6: "Batman Is Riled"'),
(1234, 'Batman: Season 1, Episode 7: "Instant Freeze"'),
(5678, 'Batman: Season 2, Episode 9: "The Greastest Mother of Them All"'),
(5678, 'Batman: Season 2, Episode 7: "The Spell of Tut"'),
(5678, 'Batman: Season 2, Episode 6: "Barbecued Batman?"'),
(5678, 'Batman: Season 2, Episode 3: "Hot Off the Griddle"'),
(9012, 'Batman: Season 3, Episode 24: "The Joker''s Flying Saucer"'),
(9012, 'Batman: Season 3, Episode 25: "The Entracing Dr. Cassandra"'),
(9012, 'Batman: Season 3, Episode 26: "Minerva, Mayhem and Millionaires"')
;
select id, substring(title,1,locate(":",title)-1) title,
group_concat(title SEPARATOR ";") as description
from dvd
group by ID
| ID | title | description |
|------|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1234 | Batman | Batman: Season 1, Episode 6: "Batman Is Riled";Batman: Season 1, Episode 7: "Instant Freeze" |
| 5678 | Batman | Batman: Season 2, Episode 9: "The Greastest Mother of Them All";Batman: Season 2, Episode 7: "The Spell of Tut";Batman: Season 2, Episode 6: "Barbecued Batman?";Batman: Season 2, Episode 3: "Hot Off the Griddle" |
| 9012 | Batman | Batman: Season 3, Episode 24: "The Joker's Flying Saucer";Batman: Season 3, Episode 25: "The Entracing Dr. Cassandra";Batman: Season 3, Episode 26: "Minerva, Mayhem and Millionaires" |
你知道NF吗?看一下用什么编程语言编写的group concat函数?@lxer我正准备用纯语言编写mysql@MarshallTigerus先生,把它写在答案栏,这样我就可以接受了。