[英]How to compare row data to my input data in sqlite3 python?
Im having trouble comparing if a certain data exist in my table based on my input. 我无法根据输入比较表中是否存在某些数据。 Lets say my input data is: 可以说我的输入数据是:
x = 1
then my table consists of 6 rows of numbers: 然后我的表由6行数字组成:
[(0,), (1,), (2,), (3,), (4,), (5,)]
I compare my input just like this: 我像这样比较我的输入:
c.execute("""SELECT num from tb_numbers""")
table = c.fetchall()
if x in table:
do something....
After running, it does not go in the if statement. 运行后,它不会进入if语句中。 What am i doing wrong here? 我在这里做错了什么? Note: "num" in tb_numbers is an INTEGER 注意:tb_numbers中的“ num”是一个整数
c.execute("""SELECT num from tb_numbers""")
table = c.fetchall()
x = 1
for each_value in table:
if each_value[0] == x:
print("Yeah! Find: {0}".format(each_value[0]))
If you're looking for just one value, you can end the for loop after finding the value to deliver performance. 如果只寻找一个值,则可以在找到值以提供性能后结束for循环。
for each_value in table:
if each_value[0] == x:
print("Yeah! Find: {0}".format(each_value[0]))
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.