CS50 SQL SELECT的财务历史记录问题

CS50 SQL SELECT的财务历史记录问题,sql,cs50,Sql,Cs50,我不明白为什么我不能从我的表公文包中选择“transaction”列。我使用以下语法创建了一个表: 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));

我不明白为什么我不能从我的表公文包中选择“transaction”列。我使用以下语法创建了一个表:

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));
该交易记录了买入/卖出订单的连续计数。当我在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代码中包含事务,那么一切都正常,并且该表显示在网页上。是什么阻止我选择事务?在代码中,我包含了事务

@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)
{% 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 %}
下面的html将显示在网页上。目前,我停止了交易

@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)
{% 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 %}
{%extends“layout.html”%}
{%block title%}
历史
{%endblock%}
{%block main%}
购买日期/时间
象征
分享
价格
全部的
{历史记录中的库存百分比_info%}
{{stock.datetime}
{{stock.symbol}
{{stock.shares}
{{stock.price}}
{{stock.total}
{%endfor%}
{%endblock%}
已解决

事务
是保留字

试着把它放在括号里,看看这是否适合你。

解决了

事务
是保留字


试着把它放在括号里,看看这是否适合你。

我认为
交易
是一个保留字。试着把它放在括号里,看看这对你是否有效。成功了。SELECT语句中的[transaction]。不幸的是,我决定选择一个保留字作为变量名,但至少现在我知道了。谢谢我认为
交易
将是一个保留字。试着把它放在括号里,看看这对你是否有效。成功了。SELECT语句中的[transaction]。不幸的是,我决定选择一个保留字作为变量名,但至少现在我知道了。谢谢