在Python3中打印SQL的结果

时间:2017-10-16 15:27:32

标签: sql python-3.x printing

我想从SQL表中打印出结果,但是碰到了一堵砖墙。

这是我的代码

# Create function question_one
def question_one():
    """
    This function will return the result for question 1:
    What are the most popular three articles of all time?
    """
    query_one = """
        SELECT articles.title, COUNT(log.id) AS views
        FROM articles, log
        WHERE log.path = CONCAT('/article', articles.slug)
        GROUP BY articles.title
        ORDER BY views DESC
        LIMIT 3;
        """
    result_one = connectDatabase(query_one)
    print('1.What are the most popular three articles of all time?')
    for row in result_one:
        print(row[0], row[1]) 
    print(" ")  # Display line break for legibility

Python运行时抛出错误。谢谢你的帮助!

0 个答案:

没有答案