php - mysql 语句中的条件

标签 php mysql

我正在尝试在 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/

相关文章:

javascript - Ajax提交两条信息到php文件

php - PHP 中的多个返回值是否被接受/良好实践?

c++ - UseQueryResult 不是 mysqlpp 的成员

PHP/MySQL : Move data from old database (tables without an ID) to new database (tables with an ID)

PHP 正则表达式将捕获组变量与数字结合起来

php - PHP中如何获取客户端真实IP地址?

mysql - 使用 Jhipster 中的服务用用户上传的 CSV BLOB 实体填充第二个实体

MySQL 函数 if elseif 1064

php - 多个单选按钮ajax post

php - 使用服务器端语言进行开发但部署到静态 HTML 的最佳方式