mysql query 条件中为空时忽略
Posted 雪洗中关村
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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", 3:WHERE (@AgentID=‘‘) OR (@AgentID<>‘‘ AND A.AgentID = @AgentID)