gpt4 book ai didi

mysql - 从多列中选择多行作为一列

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

正如标题所说,我正在尝试从 Passive、Q、W、E、R 中选择不为空的行到一列中 http://i.imgur.com/SzNl9WI.png这是我尝试过的方法,但还没有成功

SELECT (Passive + Q + W + E + R) AS spellchamps
FROM champions
WHERE Patch_No='0.02' AND Champion = 'Katarina'
AND (
(Passive!='')
or(Q!='')
or(W!='')
or(E!='')
or(R!='')
)

如果我可以将它与我以前的查询结合起来会更好,该查询可以很好地选择不为空的列的名称

SELECT column_name 
from information_schema.columns, patches.champions
where
table_name = 'champions'
AND ((column_name ='Passive' and Passive!='')
or (column_name='Q' and Q!='')
or (column_name='W' and W!='')
or (column_name='E' and E!='')
or (column_name='R' and R!='')

)

AND Patch_No = '0.02'
AND Champion = 'Katarina'

编辑 这个查询给了我正确的结果,但在 1 行中,我希望结果在不同的行中

SELECT CONCAT(Passive, Q, W, E, R) AS spellchamps
FROM champions
WHERE Patch_No='0.02' AND Champion = 'Katarina'
AND (
(Passive!='')
or(Q!='')
or(W!='')
or(E!='')
or(R!='')
)

最佳答案

试试这个:

SELECT Passive AS spellchamps
FROM champions
WHERE Patch_No='0.02' AND Champion = 'Katarina' AND
Passive IS NOT NULL AND Passive != ''
UNION
SELECT Q AS spellchamps
FROM champions
WHERE Patch_No='0.02' AND Champion = 'Katarina' AND
Q IS NOT NULL AND Q != ''
UNION
SELECT W AS spellchamps
FROM champions
WHERE Patch_No='0.02' AND Champion = 'Katarina' AND
W IS NOT NULL AND W != ''
UNION
SELECT E AS spellchamps
FROM champions
WHERE Patch_No='0.02' AND Champion = 'Katarina' AND
E IS NOT NULL AND E != ''
UNION
SELECT R AS spellchamps
FROM champions
WHERE Patch_No='0.02' AND Champion = 'Katarina' AND
R IS NOT NULL AND R != ''

关于mysql - 从多列中选择多行作为一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27780997/

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