【发布时间】:2025-12-25 08:40:11
【问题描述】:
我将创建一个表,我将在其中为不同的公司插入多个值。基本上我有下表中的所有值,但我想添加一个链接到IndicatorName 的列IndicatorID,以便每个指标都有一个唯一的ID。这显然不是PrimaryKey。
我将通过多选插入数据:
CREATE TABLE abc
INSERT INTO abc
SELECT company_id, 'roe', roevalue, metricdate
FROM TABLE1
INSERT INTO abc
SELECT company_id, 'd/e', devalue, metricdate
FROM TABLE1
所以,我不知道如何添加我上面提到的IndicatorID。
编辑: 以下是我填充新表的方式:
INSERT INTO table(IndicatorID, Indicator, Company, Value, Date)
SELECT [the ID that I need], 'NI_3y' as 'Indicator', t.Company, avg(t.ni) over (partition by t.Company order by t.reportdate rows between 2 preceding and current row) as 'ni_3y',
t.reportdate
FROM table t
LEFT JOIN IndicatorIDs i
ON i.Indicator = roe3 -- the part that is not working if I have separate indicatorID table
我将为同一家公司插入不同的指标。我想要indicatorID。
【问题讨论】:
标签: sql tsql sql-insert create-table