[英]Double WHERE NOT statement sql
I have this query: 我有这个查询:
$query = "SELECT pic_square,
name,
highest_score,
num_tries,
avg_total
FROM users
WHERE NOT played_game = '0'
ORDER BY avg_total DESC";
Where I select pic_square
, name
, highest_score
, num_tries
and avg_total
FROM for all users that 当我选择
pic_square
, name
, highest_score
, num_tries
和avg_total
从所有用户
DO NOT have their played game set as ''0''. 不要将其玩过的游戏设置为“ 0”。
I would like to add another condition so I select only the users that: 我想添加另一个条件,所以我只选择以下用户:
PS: The name cannot be null, it just can be empty, I cannot change the DB structure itself. PS: 名称不能为空,只能为空,我不能更改数据库结构本身。
So how do I add these dual WHERE NOT together? 那么,如何将这两个WHERE NOT一起添加?
WHERE NOT (played_game = '0' or name = '')
要么
WHERE played_game <> '0' and name <> ''
$query = "SELECT pic_square,name,highest_score,num_tries,avg_total FROM users
WHERE NOT (played_game = '0' OR name IS NULL OR name='' )
ORDER BY avg_total DESC";
$query = "SELECT pic_square,name,highest_score,num_tries,avg_total FROM users
WHERE played_game <> '0' AND name <> '' ORDER BY avg_total DESC";
simply change condition like 只需像改变条件
where played_game <> '0' AND name <> ''
You can use this query: 您可以使用以下查询:
$query = "SELECT pic_square,
name,
highest_score,
num_tries,
avg_total
FROM users
WHERE NOT played_game = '0'
AND IFNULL(name,'') <> ''
ORDER BY avg_total DESC";
Using IFNULL
you'll get sure that NULL
values and empty values are treated just the same. 使用
IFNULL
您将确保NULL
值和空值被相同地对待。
$query = "SELECT pic_square,name,highest_score,num_tries,avg_total
FROM users
WHERE played_game != '0'
AND name NOT NULL
ORDER BY avg_total DESC";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.