簡體   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