我正在尝试在 mysql 查询中写入一个条件:
SELECT g.* FROM groups AS g
JOIN users AS u
ON u.user_posts >= g.post_min
AND u.user_posts <= g.post_max
AND u.points >= g.point_min
AND u.points <= g.point_max
AND u.uid = "'.$uid.'"
当 g.post_max 或 g.point_max 等于 0 时,语句不需要包含最大值,我应该如何编写条件
最佳答案
$sql = 'SELECT g.id,g.point_amount
FROM groups AS g
JOIN users AS u
ON u.user_posts >= g.post_min
AND (u.user_posts <= g.post_max OR (g.post_max=0 OR g.point_max=0))
AND u.points >= g.point_min
AND (u.points <= g.point_max OR (g.post_max=0 OR g.point_max=0))
AND u.uid = "'.$uid.'"
LIMIT 1';
关于php - mysql 语句中的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6896624/