数据库唯一名称和代码

Database unique name and ticker

我创建了一个 SQLITE 数据库,其中包含一些财务数据以及股票代码。数据库看起来像这样:

由于股票代码(以及名称)是唯一的,是否可以在数据库中为每个特定公司只提供一次代码? 或者我需要它作为每一行的一个条目(即这家公司的六个条目)

如果我需要六个条目,有没有办法使用 SQL 命令复制它?由于在 CSV 文件中加载了此数据,因此代码仅存在一次,因为它是唯一的。

最终我希望能够在代码/公司名称上执行 WHERE 子句以获取该公司的相关信息。

当我 运行 WHERE 子句查询时,我得到 KeyError:1

df = pd.read_sql_query("SELECT SALES, EBITDA FROM financials WHERE Ticker = 'HK001'", cnx)

如果我省略 WHERE 子句,它工作正常。

谢谢。

更新:关注评论:

cur.execute('DROP TABLE IF EXISTS financials')
cur.execute('''
CREATE TABLE "financials"(
    "Ticker" REAL,
    "Sales" REAL,
    "EBITDA" REAL,
    "index" REAL,
    "year" REAL,
    "Capitalization" REAL,
    "Entreprise Value (EV)" REAL,
    "P/E ratio" REAL,
    "Yield" REAL
)

update financials
set ticker = (
  select f.ticker
  from financials f
  where f.ticker is not null and f.rowid < financials.rowid
  order by f.rowid desc limit 1
)
where ticker is null)
''')

我不确定更新财务代码的位置。

这条语句:

SELECT SALES, EBITDA FROM financials WHERE Ticker = 'HK001'

是正确的,但它会 return 只有 Ticker = 'HK001'.
所在的行 您可以做的最好的事情是通过用正确的值填充 Ticker 列来更新 table:

update financials
set ticker = (
  select f.ticker
  from financials f
  where f.ticker is not null and f.rowid < financials.rowid
  order by f.rowid desc limit 1
)
where ticker is null