Example
Consider a database of sales, perhaps from a store chain, classified by date, store and product. The image of the schema to the right is a star schema version of the sample schema provided in the snowflake schema article.
Fact_Sales
is the fact table and there are three dimension tables Dim_Date
, Dim_Store
and Dim_Product
.
Each dimension table has a primary key on its Id
column, relating to one of the columns (viewed as rows in the example schema) of the Fact_Sales
table's three-column (compound) primary key (Date_Id
, Store_Id
, Product_Id
). The non-primary key Units_Sold
column of the fact table in this example represents a measure or metric that can be used in calculations and analysis. The non-primary key columns of the dimension tables represent additional attributes of the dimensions (such as the Year
of the Dim_Date
dimension).
For example, the following query answers how many TV sets have been sold, for each brand and country, in 1997:
SELECT P.Brand, S.Country, SUM(F.Units_Sold) FROM Fact_Sales F INNER JOIN Dim_Date D ON F.Date_Id = D.Id INNER JOIN Dim_Store S ON F.Store_Id = S.Id INNER JOIN Dim_Product P ON F.Product_Id = P.Id WHERE D.YEAR = 1997 AND P.Product_Category = 'tv' GROUP BY P.Brand, S.CountryRead more about this topic: Star Schema
Famous quotes containing the word example:
“Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.”
—Marcel Proust (18711922)