繁体   English   中英

如何选择适用于那些行中多列的条件的多行?

[英]How to SELECT multiple rows with condition that applies to multiple columns in those rows?

我有一张桌子,像:

  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..... .....'---------> stackOverflow'

只需在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 = ???;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM