如何在同一个sql查询中检查多个sql查询

时间:2017-09-12 09:46:26

标签: php mysql mysqli

如果一个是假的,那么如何检查多个sql查询然后运行第二个查询,如果第二个错误则运行第三个查询。怎么做。我感到很困惑。

SELECT (SELECT COUNT(u.`global`) 
        FROM user u 
        WHERE u.global = user.user_id AND launch=1 )as done , user_id  
FROM user HAVING done < 6

如果这个为false则运行此sql查询: -

SELECT (SELECT COUNT(u.`global`) 
     FROM user u 
     WHERE u.global = user.user_id AND launch=1 )as done , user_id  
FROM user HAVING done > 7

1 个答案:

答案 0 :(得分:0)

你可以使用一个siplle count grouo并使用OR(和分组)检查两个有条件

 SELECT COUNT(u.`global`) done,  u.user_id
 from user u
 group by user_id
 having  done <6 or done >7