我正在使用Apache derbyDB(db2)和SQL Workbench作为环境。我有1万条数据记录,我想用维表和事实表创建一个星型模式。
dwh_price_paid_records = data table
dm_price_paid_records = data mart table (facts table)
dim_time = data mart table (dimension)
DWH_PRICE_PAID_RECORDS.TRANSACTION_ID = VARCHAR(50)
DWH_PRICE_PAID_RECORDS.PRICE = INTEGER
DWH_PRICE_PAID_RECORDS.DATE_OF_TRANSFER = DATE
DIM_TIME.DATE_ID = Primary key of dim_time (autoincrement start with 1 increment by 1)
DM_PRICE_PAID_RECORDS.DATE_ID = Foreign key NOT NULL from DIM_TIME
在事实表(DM_PRICE_PAID_RECORDS)中,我只想拥有主键,价格(事实)和ID,以便与维度表建立关系,但它不起作用。
INSERT INTO DM_PRICE_PAID_RECORDS (TRANSACTION_ID, PRICE, DATE_ID) VALUES (SELECT TRANSACTION_ID FROM DWH_PRICE_PAID_RECORDS, SELECT PRICE FROM DWH_PRICE_PAID_RECORDS, SELECT DATE_ID FROM DIM_TIME join DWH_PRICE_PAID_RECORDS on DIM_TIME.DATE = DWH_PRICE_PAID_RECORDS.DATE_OF_TRANSFER WHERE DIM_TIME.DATE =
DWH_PRICE_PAID_RECORDS.DATE_OF_TRANSFER);
我希望这是结果:
TRANSACTION_ID |价格| DATE_ID
1 | 2324 | 423
2 | 52315 | 234
但是我遇到了德语错误,内容如下: “ VALUES子句必须至少包含一个元素。不允许使用空元素”
“价值观-克劳塞尔·穆斯(Klausel musstenestens)感动了元素的热情。里尔·元素(Leere Elemente)犯罪了。
非常感谢! Flippi
答案 0 :(得分:1)
我认为您想要INSERT . . . SELECT
:
INSERT INTO DM_PRICE_PAID_RECORDS (TRANSACTION_ID, PRICE, DATE_ID)
SELECT ppr.TRANSACTION_ID, ppr.PRICE, t.DATE_ID
FROM DWH_PRICE_PAID_RECORDS ppr JOIN
DIM_TIME t
ON t.DATE = ppr.DATE_OF_TRANSFER ;