Skip to content Skip to sidebar Skip to footer

How To Compare The Rows Of A Table Using Python

Sorry if the title was misleading or not very descriptive, but here is what I want I have a table with 2 columns : name|value 1.aaaa|132412 2.aaaa|234124 3.aaaa|542253 bbbb|234324

Solution 1:

You've figured out the code to get all the results, and then it sounds like you want to compare all the two-item combinations of values.

sql="select value from table where name='aaaa'"
cursor.execute(sql)
results=cursor.fetchall() # changed to results to better reflect the list structure
count = len(results)
for i inrange(0, count):
  for j inrange (i+1, count):
    print results[i][0], results[j][0]

That'll print all the pairs . . . obviously you'll want to parse them instead, and do your comparisons where the print statement is.

Post a Comment for "How To Compare The Rows Of A Table Using Python"