gpt4 book ai didi

mysql - 将列拆分为二进制矩阵

转载 作者:行者123 更新时间:2023-11-29 17:53:18 25 4
gpt4 key购买 nike

基本上我有一个这样的专栏:

+----------------+
| Marks |
+----------------+
|Maths,Phy,Che |
|Maths,Phy |
|Phy,Che |
|Che |
|Maths,Phy,Che |
|Maths,Phy,Che |
+----------------+

我也想成为这样的人

+-------------------------+-------+------+------+
| marks | Maths | Phy | Che |
+-------------------------+-------+------+------+
| Maths,Phy,Che | 1 | 1 | 1 |
| Maths,Phy | 1 | 1 | 0 |
| Phy,Che | 0 | 1 | 1 |
| Che | 0 | 0 | 1 |
| Maths,Phy,Che | 1 | 1 | 1 |
| Maths,Phy,Che | 1 | 1 | 1 |
+-------------------------+-------+------+------+

我试图使用此答案中发布的子字符串( how to split a column into multiple columns in mysql )

但我无法让它按照我想要的方式工作

最佳答案

可以使用类似值结果的列

select marks
, (marks like '%Maths%') as Maths
, (marks like '%Phy%') as Phy
, (marks like '%Che%') as Che
from my table

关于mysql - 将列拆分为二进制矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49118716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com