我有一个MySQL查询,我曾经用它来检查用户ID是否存在,我试图简化这段代码,或者至少让它变得更好。
mysql_query("SELECT * FROM levels WHERE
('0000000000000.00000000' != (uid1)) AND uid1 IS NOT NULL
AND ('0000000000000.00000000' != (uid2)) AND uid2 IS NOT NULL
AND ('0000000000000.00000000' != (uid3)) AND uid3 IS NOT NULL
AND ('0000000000000.00000000' != (uid4)) AND uid4 IS NOT NULL
AND level_unique_id = '$level_unique_id'");
例如,如果uid3
不是null
而不是0000000000000.00000000
,那么:
mysql_query("UPDATE `levels` SET `uid3` = '$UNIQUE_ID' WHERE `levels`.`level_unique_id` = '$level_unique_id'");
如何简化此SQL查询?
说明1:我知道level_unique_id
但我想要更新uid1
或uid2
或uid3
或uid4
0000000000000.00000000
不在任何列
答案 0 :(得分:0)
您可以发布数据库的完整结构。如果你需要找到关卡。然后你应该稍微改变查询以获得结果。
无需将其作为字符串0.0000000等进行比较 **将其转换为Int ** SELECT * FROM levels WHERE(cast(uid1 as Int)!= 0)AND uid1 IS NOT NULL AND(cast(uid1 as Int)!= 0)AND uid2 IS NOT NULL AND(cast(uid1 as Int)!= 0) AND uid3 IS NOT NULL AND(cast(uid1 as Int)!= 0)AND uid4 IS NOT NULL且level_unique_id =' 1'