MySQL:打开和转置列表指南
P粉103739566
P粉103739566 2023-09-07 13:24:07
0
2
289

我有一个给定的数据框:

id 数字列表
2 [1,2,5,6,7]
5 [1,2,13,51,12]

其中一列只是 id,另一列是数字列表,就像我之前从 JSON 文件中获得的那样,有没有办法仅使用 MySQL 将其转换为这种格式?

id 数字列表
2 1
2 2
2 5
2 6
2 7
5 1
5 2
5 13
5 51
5 12

我知道使用Python和pandas可以轻松完成,但在这种情况下我只需要使用MySQL,而且我真的不知道如何在MySQL中转置列表

P粉103739566
P粉103739566

모든 응답(2)
P粉883223328

您可以使用json_table()

create table myTable(id int, listofnumbers varchar(200));
insert into myTable values(2,   '[1, 2, 5, 6, 7]');
insert into myTable values(5,   '[1, 2, 13, 51, 12]');
select t.id, j.listofnumbers
from myTable t
join json_table(
  t.listofnumbers,
  '$[*]' columns (listofnumbers varchar(50) path '$')
) j;
id 数字列表
2 1
2 2
2 5
2 6
2 7
5 1
5 2
5 13
5 51
5 12
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!