Name A B C AA BB cc
--------------------------------------------------------
Name1 Data1 n Data3 3 n 15
Name2 n Data2 Data4 n 2 8
仅当 AA、BB 或 CC 不为空时,我才想从一行中选择 A、B 或 C。
所以结局会出现:
select Name, A,B,c from table where ??? AA<10 and BB<10 and CC<10
^I know this is dumb, just to help you understand my goal.
Name A B C
-------------------------
Name1 Data1
Name2 Data2 Data4
另一个例子:
select Name, A,B,c from table where ??? AA<5 and BB<5 and CC<5
^I know this is dumb, just to help you understand my goal.
Name A B C
-------------------------
Name1 Data1
Name2 Data2
再举一个例子,踢球:
select Name, A,B,c from table where ??? AA<3 and BB<3 and CC<3
^I know this is dumb, just to help you understand my goal.
Name A B C
-------------------------
Name2 Data2
谢谢阅读!
这是我根据您的帮助提出的解决方案,以防万一有人需要:
SELECT `Name`,
CASE
WHEN SIGN(`AA`)>0
THEN `A`
END A,
CASE
WHEN SIGN(`BB`)>0
THEN `B`
END B,
CASE
WHEN SIGN(`CC`)>0
THEN `C`
END C,
FROM TABLE;