Pyodbc查询只返回

2024-04-25 07:45:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚开始使用Pyodbc,我正在尝试运行一个查询,我知道使用Sequel Pro可以完美地工作。查询必须返回几行,但是我只能得到一行。在

以下是我的疑问:

with connection.cursor() as cursor:
        # Read a single record
        sql = "select `T4`.`id`, `T4`.`r_id`, `structure`.`l2_id`, `structure`.`l2_name` from (select `T3`.`id`, `T3`.`r_id`, `item`.`L6_ID` from (select `T2`.`id`, `report`.`r_id` from (select `T1`.`id` from (select `entity`.`id` from `entity` where `entity`.`id` = %s) as `T1` inner join `coverage` on `T1`.`id` = `coverage`.`id`) as `T2` inner join `report` on `T2`.`id` = `report`.`id`) as `T3` inner join `item` on `T3`.`r_id` = `item`.`r_id`) as `T4` inner join `structure` on `T4`.`l6_id` = `structure`.`l6_id`"

 cursor.execute(sql, ('id1',))
 result = cursor.fetchone()
 for row in result:
   print(row[0])

有什么想法吗?在

谢谢!在


Tags: fromreportidonasitemstructureselect