如何使用Python For Loop正确查询更改并将其写入SQLite数据库?

时间:2018-11-26 05:34:23

标签: python python-3.x sqlite python-datamodel

我需要对SQLite数据库进行一些更改,并需要使用For Loop语句来完成这些更改。

在伪代码中,我需要完成以下步骤,并希望在编写这些常规语句时有所帮助:

  1. 获取具有column_value = x的组的列表
  2. 对于该列表中的每个组,获取所有column_value的column_id
  3. 获取名为x,y和z的所有组的所有column_id。
  4. 将所有组的column_value转移到column_id。
  5. 获取父组的group_id,然后获取其父组的group_id。
  6. 将该group_id分配/更新到名为x的新组。

以上可能没有多大意义。因此,我包括了一些我一直在使用T-SQL成功查询结果的方法。我将在此SQL下面包含我编写的SQL,以使每个人都能了解我要执行的查询类型。
对于如何开始为此编写Python脚本,我没有丝毫想法。谢谢,感谢大家的耐心配合。

-- Searchs for info links tagged with POIs named PM 
select * from info where id in (select info_id from info_relations where poi_id in (select id from poi_config where name = "PM") ); 
select *,(select name from groups where id = group_id) as groupname from poi_config where name= "AM" 

-- finding all POIs name AM and renaming them to the parent group name
update poi_config
set name = (select name from groups where id = group_id)
where name = "AM" 

-- Worry about this later. Search for PM Calendars with info links
SELECT * FROM info WHERE id IN (SELECT info_id FROM info_relations WHERE poi_id IN (SELECT ID FROM poi_config WHERE name = "PM CALENDAR") );

-- 

select * from poi_config where name = "SMP"

SELECT * FROM info WHERE id IN (SELECT info_id FROM info_relations WHERE poi_id IN (SELECT ID FROM poi_config WHERE name = "SMP") );

select * from poi_config where name = "AM" AND group_id = (select group_id from poi_config)

select * from info_relations where poi_id = 413

select * from groups where id

0 个答案:

没有答案