postgresql - Datawharehouse Fact Table Geneate -
currently, building fact table base ods tables , dimension tables. ods table
1.datewisedata
sid_date
total_impressions
2.devices(mobile phone,pc,etc)
sid_date
device_id
device_name
total_impressions
3.advertiserdata
sid_date
advertiser_id
advertiser_name
total_impressions
fact table
id
sid_date
devicesid
advertiserid
total_impressions
here, facing issue join 3 table data in single fact table. in case have 3 different total impression on each table. in fact table add single total impression. how can calculate , join then. tried different join technicians didn't find perfect solution.
please handle case
are trying build dimensional (kimball) data warehouse? if so, there changes can make.
(1) don't need datewisedata.
(2) don't need total_impressions on devices.
(3) don't need total_impressions on advertiserdata.
might suggest model should more this:
calendar (id, cal_date, cal_year, cal_month, ... ) device (id, name) advertiser (id, name) impression (calendar_id, device_id, advertiser_id, impression_count)
this assumes fact can have more 1 impression. if not correct, have known "factless fact", , table should this:
impression (calendar_id, device_id, advertiser_id)
now can run queries that, example, calculate total impressions device on given date:
select device.name,count(*) impression inner join device on device.id = device_id inner join calendar on calendar.id = calendar_id calendar.cal_date = '2016-02-08' group device.name;
does meet requirement?
edit: respond question, below.
in case want first form of fact table:
impression (calendar_id, device_id, advertiser_id, impression_count)
and query find impressions advertiser looks this:
select advertiser.name,sum(impression_count) impression inner join advertiser on advertiser.id = advertiser_id inner join calendar on calendar.id = calendar_id calendar.cal_date = '2016-02-08' group advertiser.name;
if attempt carry totals anywhere else end in world of pain.
Comments
Post a Comment