我有一张像这样的表:
Users:
--------------------------------------------------------------------------------
User_id: User_name: User_email: User_has_neck: User_has_eyes: User_has_head: User_has_hair
1 | John | jon@jk.com| yes | yes | sometimes | sometimes
2 | Kate | kte@jk.com| yes | yes | sometimes | some
3 | Mark | mrk@jk.com| yes | sometimes | sometimes | sometimes
4 | Kora | sometimes | yes | yes | yes | some
5 | Acts | act@jk.com| sometimes | sometimes | sometimes | some
6 | Jerw | sometimes | yes | yes | yes | too_much
7 | Dude | sometimes | sometimes | sometimes | yes | too_much
8 | Ninja | nja@kl.com| yes | yes | yes | too_much
现在,我需要查询:
SELECT * FROM Users WHERE <NO_COLUMN_IS_EQUAL_TO_sometimes>;
列可能包含数据; 'yes'
,'some'
但NOT
'sometimes';
如何做到这一点?......任何建议都受到高度赞赏。
我试过了,
SELECT * FROM Users WHERE *#@!$%^()**#$ NO IDEA.....
&#39; ---------&gt; stackOverflow&#39;
答案 0 :(得分:2)
只需在where
子句中进行显式比较即可。这是一个例子:
SELECT *
FROM Users
WHERE 'sometimes' not in (User_has_neck, User_has_eyes, User_has_head, User_has_hair);
编辑:
在您的示例中,您可以使用以下查询生成列表:
select group_concat(column_name separator ', ')
from information_schema.columns c
where table_name = 'users' and table_schema = ???;