gpt4 book ai didi

mysql - 表格格式问题

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

我只是想知道是否可以使用一些代码来转换此表:

  ID                             Code      Procedure              
2012146322968 4 16830, 16830
2012146658928 6 16837, 16837

进入这个:

ID              Code4   Procedures4     Code6       Procedures6
2012146322968 4 16830, 16830 NULL NULL
2012146658928 NULL NULL 6 16837, 16837

非常感谢您的帮助,我在工作的过程中正努力学习 SQL。我对 SQL 还是很陌生。我想我可能需要创建一个新的临时表,但它似乎不想在 MySQL 命令提示符下工作。

最佳答案

我不完全确定你为此使用了什么逻辑,或者该数据集是否足以创建适用于整个表的查询,但你想要的要点是:

select id, 
case when code = 4 then 4 end code4,
case when code = 4 then `procedure` end procedures4,
case when code = 6 then 6 end code6,
case when code = 6 then `procedure` end procedures6
from test

demo here

值得指出的是,如果有任何代码不是 4 或 6,这将产生奇怪的结果,因为我们专门检查条件语句中的这些值。

关于mysql - 表格格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30105480/

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