我希望在col1中的record值等于con的条件下将记录放到字典中。似乎在此代码中条件采用第一条记录。
con = 2
sql = "select col1, col1 from table"
cursor.execute(sql)
results = cursor.fetchall()
dict = {}
for record in self.results:
if(record[1] == con):
dict[record [1]] = record[0]
for key, val in dict.items():
print(key, val)
结果是:
2
2 1040
2 1050
应该是:
2 1030
2 1040
2 1050
获取所有记录的方法是什么?