2016-12-03 72 views
0
SELECT logic_id 
FROM business_logic_details 
WHERE if(form_completion != 0.00,form_completion,0) = '90' 
    AND if(query_type IS NOT NULL 
     OR query_type !='',query_type,0) LIKE '%domestic%' 
    AND if(client_type IS NOT NULL 
     OR client_type !='',client_type,0) LIKE '%existing%' 
    AND if(tour_package IS NOT NULL 
     OR tour_package !='',tour_package,0) LIKE '%S%' 
    AND if(tour_type IS NOT NULL 
     OR tour_type !='',tour_type,0) LIKE '%2%' 
    AND if(currency IS NOT NULL 
     OR currency !='',currency,0) = 'INR' 
    AND if(country IS NOT NULL 
     OR country !='',country,0) = '105' 
    AND if(adults IS NOT NULL 
     OR adults !='',adults,0) = '1' 
    AND if(duration_of_stay IS NOT NULL 
     OR duration_of_stay !='',duration_of_stay,0) = '5' 
ORDER BY logic_id ASC 
+0

只是評論...你真的需要在你的'query_type'和'client_type'列使用通配符? – Bustikiller

+0

是的,這些列有逗號分隔值。我們將搜索這些逗號分隔值中的一個或多個值。 –

回答

1

對於使用COALESCE功能:

SELECT logic_id 
FROM business_logic_details 
WHERE COALESCE(form_completion, 90) = 90 
    AND COALESCE(query_type, 'domestic') LIKE '%domestic%' 
     ... 

我也強烈建議比較整數作爲整數,而不是字符串:

好:0 = 90
不好:0 = '90'

+0

這不是預期的返回result.same結果作爲我的查詢返回。 –

+0

編輯我的答案以反映您的需求。將第二個參數作爲期望值,所以在空值的情況下它將被評估爲真。 –

+0

是的,我得到了預期的結果。謝謝,我真的很感謝你的幫助。 –