import sqlite3
conn = sqlite3.connect('cj.db')
cur = conn.cursor()
a = cur.execute("SELECT * FROM student").fetchall()
conn.commit()
conn.close()
s = 0
for i in a:
s = s + i[1]
print(s)
cj.db的student表内容如下:
| name | math | chinese |
|--------|------|---------|
| 李雷 | 100 | 99 |
| 韩小 | 98 | 91 |
| 张晓宇 | 96 | 99 |