这些命令怎么给我“缺少From子句”?

select name,count(path) as num from authors join articles on author.id=articles.author join log on log.path=concat('/article/', articles.slug) group by authors.name order by num desc;




select title, count(path) as num from articles join authors on articles.author = authors.id join log on log.path = concat('/article/',articles.slug) group by title, path, authors.name order by num desc limit 3;


这是我完整的python代码:


import psycopg2
db = psycopg2.connect(database="news")
c=db.cursor()
c.execute("""
    select title, count(path) as num from articles join authors on articles.author = authors.id join log on log.path = concat('/article/',articles.slug) group by title, path, authors.name order by num desc limit 3;

    """)
c.execute("""select name,count(path) as num from authors join articles on author.id=articles.author join log on log.path=concat('/article/', articles.slug) group by authors.name order by num desc;""")
rows=c.fetchall()
print (rows)
db.close


显示的错误如下:
psycopg2.errors.UndefinedTable:表“ authors”缺少FROM子句条目
第1行:...,作者的num(path)个数字加入author.id = ...上的文章

最佳答案

author.id应该更改为authors.id

关于python - 查询错误-缺少表的FROM子句条目-SQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57282056/

10-10 06:48