@:'str'和'str'的Python和SQLite不支持的操作数类型-@无类似问题

时间:2019-03-16 15:02:23

标签: for-loop types operands

这是一段包含SQLite查询的Python3代码。

查询在SQLite浏览器中运行没有问题,但是从Python运行查询时出错:

conn = sqlite3.connect('emaildb.sqlite')
cur = conn.cursor()
cur.execute('DROP TABLE IF EXISTS Counts')
cur.execute('CREATE TABLE Counts (org TEXT, count INTEGER)')
cur.execute('INSERT INTO Counts (org,count) SELECT SUBSTR(email, (SELECT INSTR(email,'@'))) AS org, SUM(count) as count FROM Em GROUP BY org ORDER BY count DESC')

 rows = cur.fetchall()

for row in rows:
    print(row)

错误是:

  (p)中的

TypeError追溯(最近一次通话最近)5 cur.execute('CREATE TABLE Counts(org TEXT,count INTEGER)')----> 6 cur.execute('INSERT INTO Counts(org,count )SELECT SUBSTR(email,(SELECT INSTR(email,'@')))AS org,SUM(count)as count FROM Em GROUP BY org ORDER BY count DESC')7 8行= cur.fetchall()

     

TypeError:@:'str'和'str'不受支持的操作数类型

我找到了原因,但是仍然有问题...它不是INSERT的 在插入的开始和结尾处应将“替换为”。“ INSERT ... DESC”

cur.execute(“ INSERT INTO Counts(org,count)SELECT SUBSTR(email,(SELECT INSTR(email,'@'))))AS org,SUM(count)as count FROM Em GROUP BY org ORDER BY count DESC')。

但是它不执行INSERT,有什么想法吗?

0 个答案:

没有答案