gpt4 book ai didi

mysql - 获取动态列值

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

我有一个学生表,其中包含:

  student_id , prefered_cell , cell_1 , cell_2 , cell_3 

现在在首选单元格值下我们有 (cell_1,cell2,cell3)

获取 mysql 中首选单元格值的最佳方法是什么?

这些是可用的行:

1 , 'cell_1' ,  '123-321-1231' , '431-2133-321' , '123-123-4111'
2 , 'cell_2' , '122-333-3333' , '455-123-123' , '123-421-2345'

所以我想知道学生 1 和 2 的首选号码:

将得到:

1 , '123-321-1231'
2 , '455-123-123'

最佳答案

尝试这个查询。

Select student_id, case when prefered_cell = 'cell_1' then cell_1 
when prefered_cell = 'cell_2' then cell_2
when prefered_cell = 'cell_3' then cell_3
else '0'
End as cell_value from student

关于mysql - 获取动态列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15434012/

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