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)
上一篇:XCode中设置字体大小


下一篇:python练习题-day21