我有这个问题:
$query = "SELECT pic_square,
name,
highest_score,
num_tries,
avg_total
FROM users
WHERE NOT played_game = '0'
ORDER BY avg_total DESC";
我为所有用户选择pic_square
,name
,highest_score
,num_tries
和avg_total
FROM
不要将他们玩过的游戏设置为' 0''
我想添加其他条件,因此我只选择以下用户:
PS: 名称不能为空,它只能为空,我无法更改数据库结构本身。
那么如何将这些双重WHERE一起添加?
答案 0 :(得分:2)
WHERE NOT (played_game = '0' or name = '')
或
WHERE played_game <> '0' and name <> ''
答案 1 :(得分:1)
$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";
答案 2 :(得分:1)
$query = "SELECT pic_square,name,highest_score,num_tries,avg_total FROM users
WHERE played_game <> '0' AND name <> '' ORDER BY avg_total DESC";
只需改变条件,如
where played_game <> '0' AND name <> ''
答案 3 :(得分:1)
您可以使用此查询:
$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";
使用IFNULL
,您可以确保NULL
值和空值的处理方式相同。
答案 4 :(得分:1)
$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";