我尝试使用python找出某年的婴儿出生方式,但收到以下错误 sqlite3.OperationalError:“ [Total Babies]”附近:语法错误
下面是代码
query = """
SELECT sum(b[Total Babies]) AS TotalBoys, sum(g[Total Babies]) AS TotalGirls
FROM BOYS b JOIN GIRLS g ON b.RANK = g.RANK
"""
c.execute(query)
res = c.fetchone()[0]
num_boys = int(res["TotalBoys"])
num_girls = int(res["TotalGirls"])
num_babies = num_boys + num_girls
答案 0 :(得分:0)
我认为您需要在表名和列名之间使用句点.
,因此请尝试使用:-
query = """
SELECT sum(b.[Total Babies]) AS TotalBoys, sum(g.[Total Babies]) AS TotalGirls
FROM BOYS b JOIN GIRLS g ON b.RANK = g.RANK
"""