简体   繁体   中英

How do I populate a fact table from more than one table

I am doing a school assignment but I do not know how to populate a fact table. My query to do it is

Select CustomerID from dim_cust
Select ProductID from dim_product
select InvoiceID from dim_invoice

insert into [dim_fact] ([CustomerID], [ProductID], [InvoiceID]);

The dim_* are all tables that I filled in manually.

I get also get an "Incorrect syntax near ')'" error. I also have a column that will have the total number of invoices in the fact table (dim_fact).

Any help is greatly appreciated, thank you!

Code

Product Table

Invoice Table

Customer Table

fact table

I assume that invoice table has both customerid and productid information. So you can join dim_cust and dim_invoice table to get what you want.

insert into [dim_fact] 
select c.[CustomerID], i.[ProductID], i.[InvoiceID]
from dim_cust c inner join dim_invoice i on c.customerid=i.customerid;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM