目前正在使用 SQLite 和 Pandas 学习数据科学。处理政治捐款数据集。我想知道WHERE contributors.candidate_id = candidates.id
连接两个表时下面代码的目的是什么。鉴于我的目标是为特定候选人提取贡献者并从另一个表中包含他们的姓名,如果没有这个条件,输出会不会相同?
implicit_join_sel = """
SELECT
contributors.last_name, contributors.first_name, contributors.amount, candidates.last_name
FROM
contributors, candidates
WHERE
contributors.candidate_id = candidates.id
AND candidates.last_name = 'Obama';
"""
db.cursor().execute(implicit_join_sel)
输出:
contributors.last_name contributors.first_name contributors.amount candidates.last_name
0 Buckler Steve 50.0 Obama
1 Buckler Steve 25.0 Obama
2 Buckheit Bruce 100.0 Obama
3 Buckel Linda 2300.0 Obama
4 Buckel Linda -2300.0 Obama
仅供参考的表格摘要:
--Candidates--
id first_name last_name middle_name party
0 33 Joseph Biden NaN D
1 36 Samuel Brownback NaN R
--Contributors--
last_name first_name middle_name street_1 street_2 city state zip amount date candidate_id
0 Agee Steven NaN 549 Laurel Branch Road NaN Floyd VA 24091 500.0 2007-06-30 16
4 Akin Charles NaN 10187 Sugar Creek Road NaN Bentonville AR 72712 100.0 2007-06-16 16