SQL SELECT 的 CS50 财务历史问题

CS50 Finance History Problem with SQL SELECT

我不明白为什么我不能 SELECT 我的 TABLE 投资组合中的 'transaction' 专栏。我使用以下语法创建了一个 TABLE:

CREATE TABLE 'portfolio' ('transaction' integer primary key autoincrement, 
'datetime' datetime, user_id bigint, 'symbol' varchar(5), 'price' numeric(8, 
2), 'shares' integer, 'total' numeric(8, 2));

交易保留 运行 个 buy/sell 个订单。当我在 SELECT 语句中有交易时,它给我一个错误,见下文:

RuntimeError: near "transaction": syntax error [SQL: 'SELECT transaction, 
datetime, symbol, shares, price FROM portfolio WHERE user_id = 2'] 
(Background on this error at: http://sqlalche.me/e/e3q8)

如果我不在 python 代码中包含交易,那么一切正常并且 table 会显示在网页上。是什么阻止我选择交易?在代码中,我包含了事务。

@app.route("/history")
@login_required
def history():
    """Show history of transactions"""
    #create table
    history = db.execute("SELECT transaction, datetime, symbol, shares, price FROM portfolio WHERE user_id = :user_id", user_id = session["user_id"])

    history_info = []
    for info in history:
        transaction = info["transaction"]
        datetime = info["datetime"]
        symbol = info["symbol"]
        shares = info["shares"]
        price = info["price"]
        total = abs(shares * price)
        history_info.append({"transaction":transaction, "datetime":datetime, "symbol":symbol, "shares":shares, "price":price, "total":total})

    return render_template("history.html", history_info = history_info)

下面的html是网页上会显示的内容。目前,我停止了交易。

{% extends "layout.html" %}

{% block title %}
    History
{% endblock %}

{% block main %}
    <table class="table table-bordered">
        <thead>
            <th>Purchase Date/Time</th>
            <th>Symbol</th>
            <th>Shares</th>
            <th>Price</th>
            <th>Total</th>
        </thead>
        <tbody>
            {% for stock in history_info %}
                <tr>
                    <td>{{ stock.datetime }}</td>
                    <td>{{ stock.symbol }}</td>
                    <td>{{ stock.shares }}</td>
                    <td>{{ stock.price }}</td>
                    <td>{{ stock.total }}</td>
                </tr>
            {% endfor %}
        </tbody>
   </table>
{% endblock %}

已解决....

transaction 是保留字。

试着把它放在方括号中 [transaction] 看看是否适合你。