从多列中选择多行作为一列
Selecting multiple rows from multiple columns as one column
正如标题所说,我正在尝试 select 被动、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!='')
)
如果我可以将它与我以前的查询结合起来会更好 selects 不为空的列的名称
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'
EDIT 这个查询给了我正确的结果,但是在 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 != ''
您可以使用CONCAT
SELECT CONCAT(Passive, Q, W, E, R) AS spellchamps
FROM champions
WHERE Patch_No='0.02' AND Champion = 'Katarina'
AND '' NOT IN (Passive, Q, W, E, R)
正如标题所说,我正在尝试 select 被动、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!='')
)
如果我可以将它与我以前的查询结合起来会更好 selects 不为空的列的名称
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'
EDIT 这个查询给了我正确的结果,但是在 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 != ''
您可以使用CONCAT
SELECT CONCAT(Passive, Q, W, E, R) AS spellchamps
FROM champions
WHERE Patch_No='0.02' AND Champion = 'Katarina'
AND '' NOT IN (Passive, Q, W, E, R)