如何将NOT NULL
与AND
和OR
结合起来?
此查询的输出正确。它从rate_spread列中输出非null:
SELECT action_taken, action_taken_name, applicant_ethnicity,
applicant_ethnicity_name, applicant_income_000s, county_name,
loan_amount_000s, rate_spread
FROM usa_cfpb_hmda.2007
WHERE rate_spread is NOT NULL
LIMIT 10
但是,添加约束后,Not Null
不再起作用。但是OR
确实可以工作。如本例所示:
SELECT action_taken, action_taken_name,
applicant_ethnicity, applicant_ethnicity_name,
applicant_income_000s, county_name, loan_amount_000s,
rate_spread
FROM usa_cfpb_hmda.2007
where rate_spread is NOT NULL
and action_taken = 1
OR action_taken = 6
限制10
答案 0 :(得分:2)
您必须确定逻辑的优先级(即使用括号):
where rate_spread is not null and
(action_taken = 1 or action_taken = 6);
答案 1 :(得分:0)
我相信您需要用括号将您的病情分组
SELECT action_taken, action_taken_name,
applicant_ethnicity, applicant_ethnicity_name,
applicant_income_000s, county_name, loan_amount_000s,
rate_spread
FROM usa_cfpb_hmda.2007
where rate_spread is NOT NULL
and (action_taken = 1
OR action_taken = 6)
因此,SQL将条件解释为:在action_taken = 1或action_taken = 6中,并且rate_spread不为空。