SQL IS NULL检查没有给出正确的结果

时间:2018-10-19 13:59:44

标签: mysql sql

我有三个表:>>> example = dict_all(iterable) #if iterable is the example dictionary above #the result would be >>> print(example) (False, 'comp_type') #which means #example[0] is a Truthy or Falsey for the value in the key #they key is example[1] mm_memberscmn_addresses

mm_member_statement_delivery_options中,我有-> mm_membersmember_idmember_number

member_name中,我有-> cmn_addressesreference_idreference_typeemail列 并且这里addressreference_id

member_id中,我有-> mm_member_statement_delivery_optionsmember_id

我希望所有拥有statement_delivery_methodmember_numbers且在mm_member_statement_delivery_options中的statement_delivery_method IN(2,3)都没有电子邮件,并且reference_type = 3

我在下面的查询中生成了这个,没有得到想要的结果

cmn_addresses

1 个答案:

答案 0 :(得分:0)

Hope it will work for you :)

SELECT 
DISTINCT mm_members.member_number AS MEMBER_NUMBER, 
TRIM(CONCAT(mm_members.first_name,' ',mm_members.last_Name)) AS MEMBER_NAME, 
cmn_addresses.email AS MEMBER_EMAIL, 
mm_member_statement_delivery_options.statement_delivery_method 
FROM mm_members 
JOIN cmn_addresses ON cmn_addresses.reference_id = mm_members.member_id AND cmn_addresses.reference_type = 3 
JOIN mm_member_statement_delivery_options ON mm_member_statement_delivery_options.member_id = mm_members.member_id 
WHERE (cmn_addresses.email IS NULL OR cmn_addresses.email = '') 
AND mm_member_statement_delivery_options.statement_delivery_method IN ('2','3') 
ORDER BY MEMBER_NUMBER;