type
Post
Created date
Nov 3, 2022 11:52 AM
category
Data Science
tags
Data Warehousing
status
Published
Language
English
From
School
summary
slug
password
Author
Jason Ching Yuen Siu
Priority
Featured
Featured
Cover
Origin
Type
URL
Youtube
Youtube
icon
Summary
In principal, a Bridge Table is used under three scenarios:
- Indirect relationship with Fact table. When it is impossible to have a dimension connected directed to the Fact table, because simply there is no relationship between this dimension and the Fact table (e.g. in the Product Sales case study, it is impossible to have a direct link from SupplierDim to ProductSalesFact)
- Many-to-Many relationship. When an entity (which will become a dimension) has a many-many relationship with another entity (dimension) in the E/R schema of the operational database (e.g. Supplier and Stock has a many-many relationship).
- Temporal dim. When temporality aspect (data history) is maintained in the operational database and the bridge table can be used to accommodate the dimension that has temporal attributes (e.g. product supply history is maintained in the second snowflake schema example)
And when it is used, we will implement:
1) Weight Factor and 2) List aggregate
Why a dimension cannot be connected directly to the FACT?
a) The Fact table has a fact measure, and the dimension has a key identity. In order to connect a dimension to the Fact, the dimension’s key identity must contribute DIRECTLY to the calculation of the fact measure.
- Unfortunately, this cannot happen if the operational database does not have this data, so we need to use Bridge Table.
b) The op. database does not have this data if the relationship between two entities in the operational database that hold the information about dimension’s key identity and the intended fact measure is a MANY-to-MANY relationship.
What is weight factor?
- To estimate the contribution of a dimension in the calculation of the fact measure
- Because this is only an estimate, a weight factor is optional.
create table TripDim2 as select T.TripID, T.TripDate, T.TotalKm, 1.0/count(*) as WeightFactor from Trip T, Destination D where T.TripID = D.TripID group by T.tripid, T.tripdate, T.totalkm;
What is list aggregate?
Concatenate the list
create table TripDim3 as select T.TripID, T.TripDate, T.TotalKm, 1.0/count(D.StoreID) as WeightFactor, listagg (D.StoreID, ’_’) within group (order by D.StoreID) as StoreGroupList from Trip T, Destination D where T.TripID = D.TripID group by T.TripID, T.TripDate, T.TotalKm;
Case study 1: A Product Sales Case Study
Context:
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F1e6b1ffe-8e27-434d-b3df-06c1706da978%2FUntitled.png%3Ftable%3Dblock%26id%3D40a1ce7a-9eac-4bfe-96af-fac4812de73c%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DzypSjJFE35q6L08VZKqAHSPyToyQP2GmjGB2TtCc1h0?table=block&id=40a1ce7a-9eac-4bfe-96af-fac4812de73c&cache=v2)
Solution
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F2ae797e7-6b06-4205-bcd6-96fb456b99e1%2FUntitled.png%3Ftable%3Dblock%26id%3Df6530f31-fafe-42ad-ac9f-2f0107445d04%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3D082twVcJYfiuPikFjlLDWcUNMK9qNpvaZeRnV0i1lD8?table=block&id=f6530f31-fafe-42ad-ac9f-2f0107445d04&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fd94a246e-5d5d-425f-b87c-dfc19814b6c6%2FUntitled.png%3Ftable%3Dblock%26id%3Dca339275-9a4c-4cbe-a707-e4293c69ed10%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DbtbQhBiuxRz1irdyij9mCZyPKeFA_rQMitHiLk1LEEg?table=block&id=ca339275-9a4c-4cbe-a707-e4293c69ed10&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Ff4d89e38-e4f2-422d-a101-426d2e33b867%2FUntitled.png%3Ftable%3Dblock%26id%3D05d4c83f-480c-45fb-8986-ae6f5687888a%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DATU8-9ddtb9MmvCelreQG4BuywMdgNu3YVwm6pGwOKk?table=block&id=05d4c83f-480c-45fb-8986-ae6f5687888a&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F74f6ba75-56d3-428a-a1ec-1d1b9e431371%2FUntitled.png%3Ftable%3Dblock%26id%3Dbad9f267-f576-4dd7-b4d1-798d417a0e6c%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DbKKzfdc0I5RyvkT-FVIJIT4NBX35HQcQmBq0qMrRtZE?table=block&id=bad9f267-f576-4dd7-b4d1-798d417a0e6c&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F26e0cce3-c03c-40bf-b700-568b19dd4466%2FUntitled.png%3Ftable%3Dblock%26id%3D7cfaa8d4-feb8-4a20-91db-548b041f84bd%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DFp03n2IAN8QP6IbN2amnDI8FLWJei6OXHh0g9ARGO8Q?table=block&id=7cfaa8d4-feb8-4a20-91db-548b041f84bd&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F5d2d5705-c482-4403-a73b-4e7a59af28dd%2FUntitled.png%3Ftable%3Dblock%26id%3D72314be4-3994-4b63-a792-5954f66f9a7b%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DKITcFitI35Ib2y2PwtKXqybRdwNlh4iBEUFpkpQ_46g?table=block&id=72314be4-3994-4b63-a792-5954f66f9a7b&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fe711d2eb-4bdb-43e3-8b9f-38cb0fbc1053%2FUntitled.png%3Ftable%3Dblock%26id%3D68500e5c-0c51-4b7d-9cf9-dc97047f5508%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3D5_xW65YzX8zB6du_sh10tpbQTsxYV_OvUnTHy4tQoew?table=block&id=68500e5c-0c51-4b7d-9cf9-dc97047f5508&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F615eefbb-b690-4bf5-9475-27df52f43db5%2FUntitled.png%3Ftable%3Dblock%26id%3D8952f20b-96f0-49a6-88ee-eac9a23a01fa%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DbHKgb5U-4tKKfGXmG6158QENKsh8_swUKaX-LiyDJjQ?table=block&id=8952f20b-96f0-49a6-88ee-eac9a23a01fa&cache=v2)
Sales
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F7bc2abd2-b1e7-420b-bfa4-6006ee374e90%2FUntitled.png%3Ftable%3Dblock%26id%3D6f2cd58d-c163-4ae2-9bfb-ea8597cbaa2c%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DHSUquASDzOa5U0e-TW-r-nwkU-UpwrGcvxMBf6gyJ-U?table=block&id=6f2cd58d-c163-4ae2-9bfb-ea8597cbaa2c&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fa92f22d1-d07a-4ea3-829d-a535a2afe9d0%2FUntitled.png%3Ftable%3Dblock%26id%3D05665c00-afeb-42fc-8eba-9b9689a6df62%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DbHtk3YHYbCfj2aF1MUoTDHAiW0hYIoFxkv-TM2lhXUU?table=block&id=05665c00-afeb-42fc-8eba-9b9689a6df62&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fc0f96ed7-5cb6-4276-81fa-5cf6b5c05671%2FUntitled.png%3Ftable%3Dblock%26id%3D4ed3a132-a265-45ba-809b-e4e9b31c413e%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DmGvjSXg5mQn99CYrOsBSu3bq7NEHA9_oMhX1tjUF9XQ?table=block&id=4ed3a132-a265-45ba-809b-e4e9b31c413e&cache=v2)
Why isn't this report correct?
- This report seems correct but it is impossible to be produced.
- Because in the E/R diagram, it shows that one supplier may supply many products (Many2Many) -- so the sales do not record which supplier supplied a product.
- Therefore, we can conclud that 1) there is no direct relationship between suppliers and total sales. 2) supplier information is not available in the sales of a particular product.
If the report is not correct, what should we do?
- We move the Supplier Dimension from being connected to the Fact and to create a relationship with the Product Dimension — that means we added a Bridge Table between Product Dimension and Supplier Dimension.
- The bridge table has three information in which we can “drill down” for information on products: location, date and quantity of supplies.
Why are there three kinds of representations? What is the difference?
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fe679fbe2-a584-41af-9f5b-656f4a76f9df%2FUntitled.png%3Ftable%3Dblock%26id%3D841a3f86-c4ad-4af6-aed8-101e1a7d110a%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3D2xJYVGT0SCZBPMNoUAeTGuW006CTP5t5N5ysIgOBUS8?table=block&id=841a3f86-c4ad-4af6-aed8-101e1a7d110a&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F7e9f360d-bca8-40c0-afa3-d21d8c4dbccc%2FUntitled.png%3Ftable%3Dblock%26id%3Deae8018f-52b7-4483-bbcf-494f69472afe%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3Dp0DY85G0yd-sAmR873NLuUajJFry1FuqdWSA4cxyZwA?table=block&id=eae8018f-52b7-4483-bbcf-494f69472afe&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F606bd78e-49c4-4b09-8985-506084993ccd%2FUntitled.png%3Ftable%3Dblock%26id%3D5688d50f-9be5-45d2-b147-fbca1dabd17e%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DZB10H_gthm3Kd5MZBDhsoGIutMZ2b3q6JWRKTEKMJYE?table=block&id=5688d50f-9be5-45d2-b147-fbca1dabd17e&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Ff6ab04fc-f3c2-48df-8210-579702c91073%2FUntitled.png%3Ftable%3Dblock%26id%3Df3683f5a-3b3f-4493-aa5c-11aea383347f%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DLsSuse_6k9qHgxFFKRxWsvn6vUpuLDK6rov6uaFMzOY?table=block&id=f3683f5a-3b3f-4493-aa5c-11aea383347f&cache=v2)
Figure 5.7 for further details. 5.7 is where you — as the manager —want to see the detail of the dim that cannot be directly connected (i.e., Supplier). For example, we know that product A is performing particularly well, and we want to further information about details of the supply history and the suppliers.
Figure 5.8 for temporal dim. 5.8 is where the operational database does not maintain a master list of all suppliers (assume that each supplier may supply any product in an ad hoc manner), we will not have the Supplier Dimension in the schema in the figure 5.8. Instead, we will only have the Bridge Table; however, for each Product-Supplier pair, we will have Location and Date implemented as a weak entity, because for each productsupplier, there are multiple supplies.
Therefore, the Bridge Table here acts as a temporal dimension. This means, for each product, there is a list of the history of supplies.
Figure 5.9 for non-temporal warehouse. 5.9 is where the history is not needed (in a non-temporal data warehouse). You can see that the Product Supplier Bridge Table will only have ProductNo and SupplierName attributes, without the history of supplies.
Case study 2: A Truck Delivery Case Study
Context
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F19fc9771-06d7-4d87-a956-c253edef830d%2FUntitled.png%3Ftable%3Dblock%26id%3D183bee4a-d4fb-4952-953e-64ca4034e7f8%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DPQX17HRplA723onXHPlY6r4TF_4bt-mNHbtSEcVinmc?table=block&id=183bee4a-d4fb-4952-953e-64ca4034e7f8&cache=v2)
Solution
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fa8a3d1f0-0f4f-4ea4-81d9-8fa70b73c18a%2FUntitled.png%3Ftable%3Dblock%26id%3Dea5c4713-225a-4e38-8e8e-d325d67c8796%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DKKVl7-qRRKcClms3MSajSBquflBBz6NUVTY1WiRjxoc?table=block&id=ea5c4713-225a-4e38-8e8e-d325d67c8796&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F6fe44d89-c594-4450-b888-95c8da62eff5%2FUntitled.png%3Ftable%3Dblock%26id%3Da72478b8-ca22-4468-b8ca-9d28651f578d%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DH0KAyrW3wmYM0dNw6NXhvrppvL_4dyCDHpjURgL6JzA?table=block&id=a72478b8-ca22-4468-b8ca-9d28651f578d&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fbc45176b-4c50-4db7-9954-14f90315ebf3%2FUntitled.png%3Ftable%3Dblock%26id%3D90ff23bf-0d6e-4489-883f-9a344a5b7530%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3D8-9PtA3HDPstRH1bvAE-QchxPsYDaGhg0SFfI7Qg7VU?table=block&id=90ff23bf-0d6e-4489-883f-9a344a5b7530&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F908ceaee-ffac-4a63-9db1-e65d8a4aa9ac%2FUntitled.png%3Ftable%3Dblock%26id%3D03f435a4-b4b3-457f-b821-d667d9dad9b2%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3Dr55m4OUMnHMtmf3XqZCdfnYu_jhU6bsxM9AJRsw_u-k?table=block&id=03f435a4-b4b3-457f-b821-d667d9dad9b2&cache=v2)
A Truck Delivery Case Study
A trucking company is responsible for picking up goods from the warehouses of a retail chain company and delivering the goods to individual retail stores. A truck carries goods on a single trip, which is identified by TripID and delivers these goods to multiple stores. Trucks have different capacities for both the volumes they can hold and the weights they can carry.
Currently, a truck makes several trips each week. An operational database is being used to keep track of the deliveries, including the scheduling of trucks to provide timely deliveries to stores.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F41b604a7-0016-4aeb-84d4-a583e3942df7%2FUntitled.png%3Ftable%3Dblock%26id%3D857ea257-c6c1-4905-b95e-2b792a9dd642%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DwLLmMoR8SXt-ISs4yGqYvlDR7cnzdwyzywrKqHfwH5I?table=block&id=857ea257-c6c1-4905-b95e-2b792a9dd642&cache=v2)
(i) a trip may pick up goods from many warehouses (i.e. a many-many relationship between Warehouse and Trip);
(ii) a trip uses one truck only, and obviously a truck may have many trips in the history (i.e. a many1 relationship between Trip and Truck);
(iii) a trip delivers goods (e.g. TVs, fridges, etc.) potentially to several stores (a many-many relationship between Trip and Store, which is represented by the Destination table)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fb35092a2-f307-418e-8400-28442b6b9d14%2FUntitled.png%3Ftable%3Dblock%26id%3D331f2e34-a679-475a-b703-0d70eed3055a%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3Dfyrmt4HuEs2P4OPB-o_9fOIjtZR5CnwZivkPaINnppU?table=block&id=331f2e34-a679-475a-b703-0d70eed3055a&cache=v2)
Why isn't this report correct?
If you look at the Tables 5.9, 5.10, 5.11, 5.12, 5.13, and 5.14, you will see that there is no direct relationship between Store and Total Delivery Cost in the Fact Table.
This is due to the many-many relationship between the Trip entity and Store entity in the E/R diagram of the operational database.
If the report is not correct, what should we do?
Solution 1: Using a Bridge Table
- To solve this problem, a Bridge Table can be used, as shown in Fig. 5.12.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fbc8d79c2-417a-47b5-b3aa-e0826c8544ea%2FUntitled.png%3Ftable%3Dblock%26id%3D5452511c-f90b-4c4e-8c69-e116a90a5bf3%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DrqganvyRgoYmbKheXHjMhef5K31tgfQ_8yf1J7QTnBI?table=block&id=5452511c-f90b-4c4e-8c69-e116a90a5bf3&cache=v2)
- For this solution, we can only see the cost for Trip1 is $x and Trip1 delivered to y number of stores. For example, it is found that the length of trip1 is 370 km on 14 April using Truck1, and the cost per kilometre for Truck1 is $1.20. Trip1 delivered goods to five stores at a cost of $444 (370 * 1.2).
Solution 2: Add a Weight Factor Attribute
Problem is that it is impossible to calculate the delivery cost for each of these five stores for Trip1. So, we can estimate the total delivery cost per store, if we want to. This can be estimated through the “Weight Factor” (see the Weight Factor attribute in the Trip Dimension in Fig. 5.13).
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F3544ab4f-c56d-420e-ae8b-26c4f87156b2%2FUntitled.png%3Ftable%3Dblock%26id%3Dff139327-7347-499d-91d7-34bf7180191a%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3D8OdKWLSnhYJDj5guxi71geT3ZLSx0j64J-GgvcY3zfU?table=block&id=ff139327-7347-499d-91d7-34bf7180191a&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F582167b9-9412-4e16-b3e3-c41f59573b9d%2FUntitled.png%3Ftable%3Dblock%26id%3Df1959924-7393-4a42-8240-c9f822ac05ee%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DAzYOHS93Iputix31iSlsqWtrK7pux7sDcB6d6u-DZYk?table=block&id=f1959924-7393-4a42-8240-c9f822ac05ee&cache=v2)
A weight factor is a proportion of the trip that goes to each store for that particular trip. For example, if Trip1 went to five stores, then the Weight Factor is 0.2 (or 20%).
- This implies that each store “contributes” 20% of the total delivery cost for that trip. This is certainly inaccurate, but this is the only estimate that we can make, based on the data that we have.
The 0.2 weight factor for Trip1 does not mean that Trip1 has 20% of the total delivery cost; rather, Trip1 delivers to five stores, and each store contributes 20% (or 0.20) to the total delivery cost.
Solution 3: A List Aggregate Version
Instead of having M1, M2, M3… per trip for each row, we can concatenate all the stores passed during the trip (e.g., M1_M2_M3_M4_M8 ), and store it as an attribute.
To create the Trip Dimension table with a StoreGroupList attribute, we can use the listagg function in SQL. The listagg function has the following format:
listagg (Attr1, ’_’) within group (order by Attr1) as ColumnName
where Attr1 is the StoreID and the “” indicates that the StoreIDs are concatenated with the “” symbol (e.g. M1_M2_M3_M4_M8). If we want to list the stores listed in descending order (e.g. M8_M4_M3_M2_M1), then we use within
group (order by Attr1 Desc)
. The SQL to create the Trip Dimension table becomes:create table TripDim3 as select T.TripID, T.TripDate, T.TotalKm, 1.0/count(D.StoreID) as WeightFactor, listagg (D.StoreID, ’_’) within group (order by D.StoreID) as StoreGroupList from Trip T, Destination D where T.TripID = D.TripID group by T.TripID, T.TripDate, T.TotalKm;
Pros:
- Visually, the List Aggregate attribute (e.g. the StoreGroupList attribute in the Trip Dimension) is appealing because it is very easy to see the complete list of stores for each trip.
- A preferred option in the industry, because a group list is physically listed in the parent dimension, which may visually help the decision-makers to understand the completeness of the group list (e.g. StoreID for each Trip).
Cons:
- This information is rather redundant because we can get the same information from the Bridge Table
- A non-List Aggregate version is simpler and cleaner.
- The implementation is simpler and more straightforward.
- There is no redundant information on the stores within each trip
Case study (Lecture Activity 7): Publication
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F242ca712-a401-45c9-afdb-5818d03d12d8%2FUntitled.png%3Ftable%3Dblock%26id%3Df4f2e419-3c76-4eea-a5b5-48cec6ab009d%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DZ0NaFa5IdUdu96AJKgvnLDuo8Jdufi7FeG3-NSdvfCY?table=block&id=f4f2e419-3c76-4eea-a5b5-48cec6ab009d&cache=v2)
![You are required to build a data warehouse to analyse number of publications for each year, research field, publication type, and academic/author. Note the history of each academic job rank in the university is maintained in the database.](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F08548a1d-22c0-4a6d-89f3-f30a6820fdb3%2FUntitled.png%3Ftable%3Dblock%26id%3Db657dbc8-9da2-4f39-92cc-f3a2cad9342a%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3D07ZsTTL4QYS0xSOp7NARWu78dj_yUttDxk--_IGlq1o?table=block&id=b657dbc8-9da2-4f39-92cc-f3a2cad9342a&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F33949ce6-ceb8-4797-8536-6bfca4d45124%2FUntitled.png%3Ftable%3Dblock%26id%3D7d704502-5cf7-4cff-b6f2-9cacd63a16c0%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725796800000%26signature%3DmyRiWdThll7NKMCZyE9Vx1cqwGMjwHeITBMPIwbxRpA?table=block&id=7d704502-5cf7-4cff-b6f2-9cacd63a16c0&cache=v2)
- Author:Jason Siu
- URL:https://jason-siu.com/article%2F0885f6fd-0aa9-4f82-829d-333911d9891c
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts
FIT3003 - W4 - Data cleaning in Oracle Database
FIT3003 - W8 - Basic OLAP (CUBE & partial CUBE )
FIT3003 - W3 - Average in the Fact
FIT3003 - W11 - Active Data Warehousing
FIT3003 - W8 - SQL Notes about Cumulative and Moving Aggregates
FIT3003 - W8 - SQL Notes about RANK() OVER (PARTITION BY x ORDER BY y)