雪洗中关村

导航

mysql query 条件中为空时忽略

1.    q.ques_group传入为null或''的时候不查询此条件:
          value = "SELECT *             FROM question q WHERE  1=1 AND (q.ques_group = :quesGroup or :quesGroup is null or :quesGroup='') AND q.type = :type",

        1: (q.ques_group = :quesGroup or :quesGroup is null or :quesGroup='')
        2: (q.ques_group = ISNULL(:quesGroup, q.ques_group) OR q.ques_group = (CASE WHEN :quesGroup = '' THEN q.ques_group ELSE :quesGroup END)) :分解:
            SELECT *             FROM question q WHERE  
            1=1 AND (q.ques_group = IFNULL(:quesGroup, q.ques_group) OR q.ques_group = (CASE WHEN :quesGroup = '' THEN q.ques_group ELSE :quesGroup END)) 
            AND q.type = :type",
        3WHERE       (@AgentID='') OR (@AgentID<>'' AND  A.AgentID = @AgentID)     

 

posted on 2018-05-16 11:07  雪洗中关村  阅读(372)  评论(0编辑  收藏  举报