我的数据库将hotel_names 存储在1-7 行中,但计数存储在8-14 行中。我想根据hotel_name 存储计数。实际上我被困在某一点上。我想这样显示:
Hotel_id Hotel_name| Is_pool | Pool_count
1 cAnberra hotel 1 1.4
2 Hayat hotel 1 1.2
3 grand 1 1.0
4 New one hotel 1 1.99
5 7 hotels 1 0.98
6 New light 1 0.78
7 Lime light hotel1 0.1
但我的代码正在显示:
Hotel_id Hotel_name Is_pool Pool_count
1 cAnberra hotel 1
2 Hayat hotel 1
3 grand 1
4 New one hotel 1
5 7 hotels 1
6 New light 1
7 Lime light hotel 1
8 1.4
9 1.2
10 1.0
11 1.99
12 0.98
13 0.78
14 0.1
这是我的代码:
for hotel in myarrayUrl[ind_pos]:
print("The myarrayUrl converted to a list")
print(hotel)
c.execute("INSERT INTO hotels (hotel_name, is_pool) VALUES (?,?)" , [hotel,1])
for count in myarray[ind_pos]:
print("The myarray converted to a list")
print(count)
c.execute("INSERT INTO hotels (pool_count) VALUES (?)" , [count])
帮助我。提前致谢。
每个 INSERT 语句都会创建一个新行。
要更改现有行中的某些值,您需要执行 UPDATE。
但是,在这种情况下,您应该一次将所有值插入同一行:
for hotel, count in zip(myarrayUrl[ind_pos], myarray[ind_pos]):
c.execute('INSERT INTO hotels(hotel_name, is_pool, pool_count) VALUES (?, ?, ?)',
[hotel, 1, count])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句