db = pymysql.connect("host", "username", "*pass*","dbname", port) cursor = db.cursor() sql = "select id from arg_transaction where did=0 and bid>100000000000000" cursor.execute(sql)