[英]Select all except if specific cell value in MYSQL
I'm stuck and I can't figure it out, so I would appreciate any help. 我被卡住了,无法解决,所以我将不胜感激。
At this point i have table journal which consists of columns: 在这一点上我有表日记 ,其中包含列:
id | name | type(int) | classification | data | journalUser | start_date(default NULL)
1 | John | 1 | 2 | data123 | 1 | 10-11-2019
2 | Peter | 2 | 2 | data123 | 1 | 10-11-2019
3 | Ash | 2 | 2 | data123 | NULL | NULL
4 | BUBU | 2 | 2 | data123 | 3 | 10-11-2019
I want to make query where I select all, but with exceptions, for example: SELECT * from journal, but if column type = 2, than select this row too if journalUser = 1 AND second check if column type = 2 and start_date IS NULL, than select this row too. 我想在查询中选择所有内容,但有例外,例如:SELECT * from journal,但如果列类型= 2,那么如果journalUser = 1并且第二次检查列类型= 2并且start_date IS NULL,则也选择此行,也不要选择此行。
As the result, from table above, from query I wan to get result 结果,从上表中,从查询中我想要得到结果
id | name | type(int) | classification | data | journalUser | start_date(default NULL)
1 | John | 1 | 2 | data123 | 1 | 10-11-2019
2 | Peter | 2 | 2 | data123 | 1 | 10-11-2019
3 | Ash | 2 | 2 | data123 | NULL | NULL
That's a specific case when the type
is 2. 当
type
为2时,这是一种特殊情况。
To get the rows with type = 2
along with either (considering the expected output) journalUser = 1
or start_date = null
, this can be written this way : 要获得
type = 2
的行以及(考虑到预期的输出) journalUser = 1
或start_date = null
,可以这样写:
type = 2 AND (journalUser = 1 OR start_date IS NULL)
To make sure you have others type too, you can add an OR
condition such as : 为了确保您还有其他类型,可以添加
OR
条件,例如:
OR type <> 2.
This will give this query : 这将给出以下查询:
SELECT *
FROM journal
WHERE (type = 2 AND (journalUser = 1 OR start_date IS NULL))
OR type <> 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.