gpt4 book ai didi

mysql - SQL - SELECT 任何列具有特定值的行

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

我需要创建一个 SELECT 查询,该查询将返回至少 X 列之一具有特定值的行。

id    name    teamid     player1    player2    player3    ...    player12

1 Jane 2 43 46 12 ... 36
2 Mathew 6 12 56 18 ... 42
3 Shaun 8 53 55 12 ... 62
4 Jane 1 1 53 19 ... 34
5 Eugene 3 23 34 13 ... 44

在此表中,我有 14 列(id、名称和player1 到player12),并且想要SELECT 特定teamid 行,假设teamid=' 2',并返回该行中包含例如数字 12 的列的名称。

这对于 MySQL 来说是可能的吗?

最佳答案

如果我理解的话:

select t.*,
(case when player1 = 12 then 'player1'
when player2 = 12 then 'player2'
. . .
when player12 = 12 then 'player12'
end) player_with_12
from t
where t.teamid = 2;

您可能需要重新访问数据结构,因此每个团队玩家各有一行。

关于mysql - SQL - SELECT 任何列具有特定值的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46623625/

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