Project databanken II · 2020. 6. 3. · PROJECT DATABANKEN II . Arno Van Nieuwenhove, Illias...

Post on 26-Apr-2021

5 views 0 download

Transcript of Project databanken II · 2020. 6. 3. · PROJECT DATABANKEN II . Arno Van Nieuwenhove, Illias...

GROUP 2

ARNO VAN NIEUWENHOVE, ILLIAS DKHISSI, JORDI PERREMAN, KIMBERLY DE CLERQ, SLAV MITOV, SOUHAIB AKROUCHI

PROJECT DATABANKEN II

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 1

Deliverables ............................................................................................................................................. 2

Dashboard Chinook ............................................................................................................................. 2

Opdracht 1: Total sales per year ......................................................................................................... 2

Opdracht 2: Total sales per year per genre ......................................................................................... 3

Opdracht 3: Year most recent invoice ................................................................................................. 4

Opdracht 4: Tracks sold per artist per year top 10 ............................................................................. 4

Opdracht 5: Country existing in table ................................................................................................. 5

Opdracht 6: Last year’s sales growth per EU country ......................................................................... 5

Opdracht 7: Design data warehouse ................................................................................................... 6

Dashboard ChinookDW ....................................................................................................................... 7

Opdracht 8: Fill data warehouse ......................................................................................................... 7

Opdracht 9: Query data warehouse .................................................................................................... 8

Opdracht 10: Query result ................................................................................................................... 9

Opdracht 11: Schedule the package .................................................................................................. 11

Opdracht 12: PowerBI service report ................................................................................................ 11

ETL ..................................................................................................................................................... 12

Control flowchart .......................................................................................................................... 12

Slowly changing dimension ........................................................................................................... 12

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 2

Dashboard Chinook

Opdracht 1: Total sales per year USE Chinook; CREATE VIEW RPSalesPerYear AS( SELECT YEAR(invoiceDate) AS 'Year', SUM(Total) AS 'Total' FROM Invoice GROUP BY YEAR(invoiceDate) ); SELECT * FROM RPSalesPerYear;

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 3

Opdracht 2: Total sales per year per genre USE Chinook; CREATE VIEW RPSalesPerYearPerGenre AS( SELECT Genre.Name, YEAR(invoiceDate) AS 'Year', SUM(Total) AS 'Total' FROM Invoice JOIN InvoiceLine ON Invoice.InvoiceId=InvoiceLine.InvoiceId JOIN Track ON InvoiceLine.TrackId=Track.TrackId JOIN Genre ON Track.GenreId=Genre.GenreId GROUP BY YEAR(invoiceDate), Genre.Name ); SELECT * FROM RPSalesPerYearPerGenre;

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 4

Opdracht 3: Year most recent invoice USE Chinook; UPDATE Invoice SET InvoiceDate = DATEADD(YEAR, (SELECT (YEAR(getdate())-MAX(year(Invoicedate)))-1 FROM Invoice),InvoiceDate); SELECT * FROM RPSalesPerYear;

Opdracht 4: Tracks sold per artist per year top 10 USE Chinook; WITH top10Artist(artistID) AS ( SELECT TOP (10) Album.ArtistId FROM Invoice JOIN InvoiceLine ON Invoice.InvoiceId = InvoiceLine.InvoiceId JOIN Track ON InvoiceLine.TrackId = Track.TrackId JOIN Album ON Track.AlbumId = Album.AlbumId GROUP BY Album.ArtistId ORDER BY SUM(InvoiceLine.Quantity) DESC) (SELECT Artist.Name AS 'Artist', YEAR(Invoice.InvoiceDate) AS 'Year', SUM(InvoiceLine.Quantity) AS 'Tracks Sold' FROM Invoice JOIN InvoiceLine ON Invoice.InvoiceId = InvoiceLine.InvoiceId JOIN Track ON InvoiceLine.TrackId = Track.TrackId JOIN Album ON Track.AlbumId = Album.AlbumId JOIN Artist ON Album.ArtistId = Artist.ArtistId GROUP BY Album.ArtistId, YEAR(Invoice.InvoiceDate), Artist.Name HAVING (Album.ArtistId IN (SELECT top10Artist.artistID FROM top10Artist)));

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 5

Opdracht 5: Country existing in table A)

B)

SELECT DISTINCT Customer.Country FROM Customer WHERE Country NOT IN (SELECT name FROM

COUNTRY);

C)

UPDATE COUNTRY SET name = 'US' WHERE COUNTRY.[alpha-2] = (SELECT DISTINCT Customer.Country FROM Customer WHERE

Country NOT IN (SELECT name FROM COUNTRY) AND Country = 'US')

Opdracht 6: Last year’s sales growth per EU country USE Chinook; CREATE VIEW RPGrowthPerCountry AS WITH LastYearTotal(country, sales) AS ( SELECT c.Country, SUM(Total) FROM Invoice i JOIN Customer c ON i.CustomerId = c.CustomerId JOIN Country co ON c.Country = co.name WHERE (year(InvoiceDate) = year(getDate()) - 1) AND (co.region LIKE '%Europe%') GROUP BY Country ), TwoYearsAgoTotal(country, sales) AS ( SELECT c.Country, SUM(Total) FROM Invoice i JOIN Customer c ON i.CustomerId = c.CustomerId JOIN Country co ON c.Country = co.name WHERE (year(InvoiceDate) = year(getDate()) - 2) AND (co.region LIKE '%Europe%') GROUP BY Country )

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 6

SELECT ISNULL(l.country, t.country) AS 'Country', CAST( CASE ISNULL(t.sales, 0) WHEN 0 THEN 1999 ELSE ((ISNULL(l.sales, 0) - t.sales) / t.sales * 100) END AS int) AS 'Growth' FROM LastYearTotal l FULL OUTER JOIN TwoYearsAgoTotal t ON l.country = t.country SELECT * FROM RPGrowthPerCountry; SELECT * FROM RPGrowthPerCountry;

Opdracht 7: Design data warehouse

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 7

Dashboard ChinookDW

Opdracht 8: Fill data warehouse USE Chinook; CREATE VIEW VwDim_Artist AS SELECT ar.ArtistId AS 'ArtistID', ar.Name AS 'Name', GETDATE() AS 'Added' FROM Artist ar; CREATE VIEW VwDim_Customer AS SELECT cu.CustomerId AS 'CustomerID', cu.FirstName, cu.LastName, cu.Country co, cu.City ci, GETDATE() AS 'Added' FROM Customer cu JOIN COUNTRY co ON cu.Country = co.name; CREATE VIEW VwDim_Date AS SELECT DISTINCT CONVERT(varchar(50), i.InvoiceDate, 112) AS 'DateID', CAST(DAY(i.invoiceDate) AS INT) AS 'Day', MONTH(i.invoiceDate) AS 'Month', CAST(YEAR(i.invoiceDate)AS INT) AS 'Year', i.InvoiceDate AS 'Date' FROM Invoice i; CREATE VIEW VwDim_Genre AS SELECT g.GenreId AS 'GenreId', g.Name AS 'Name' FROM Genre g; CREATE VIEW VwDim_Track AS SELECT t.TrackId AS 'TrackID', t.Name AS Name FROM Track t; Use ChinookDW; INSERT INTO Fact_Sales(DateID,Quantity,UnitPrice,SalesAmount,milliseconds,SalesMilliseconds,GenreID,TrackID,CustomerID,ArtistID) SELECT convert(varchar(50), i.InvoiceDate, 112) as 'DateID', il.Quantity Quantity, il.UnitPrice AS 'UnitPrice', il.UnitPrice * il.Quantity AS 'TotalSalesAmount', t.Milliseconds, t.Milliseconds * il.Quantity AS 'TotalMillisecondsAmount', g.GenreId AS 'GenreId', t.TrackId AS 'TrackId', cu.CustomerId AS 'CustomerId', ar.ArtistId AS 'ArtistId'

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 8

FROM Chinook.dbo.InvoiceLine il JOIN Chinook.dbo.invoice i ON i.InvoiceId = il.InvoiceId JOIN Chinook.dbo.Track t ON t.TrackId = il.TrackId JOIN Chinook.dbo.Genre g On t.GenreId = g.GenreId JOIN Chinook.dbo.Customer cu ON cu.CustomerId = i.CustomerId JOIN Chinook.dbo.Album ab ON ab.AlbumId = t.AlbumId JOIN Chinook.dbo.Artist ar ON ar.ArtistId = ab.ArtistId;

Opdracht 9: Query data warehouse Query 1) USE ChinookDW; CREATE VIEW RPSalesPerYearDW AS( SELECT dd.[year] AS 'Year', SUM(SalesAmount) AS 'Total' FROM Fact_Sales f JOIN Dim_Date dd ON f.DateID = dd.DateID GROUP BY dd.[year] ); SELECT * FROM RPSalesPerYearDW;

Query 2) USE ChinookDW; CREATE VIEW RPSalesPerYearPerGenreDW AS( SELECT dd.[year] AS 'Year', dg.Name AS 'Genre', SUM(SalesAmount) 'Sales' FROM Fact_Sales f JOIN Dim_Date dd ON f.DateID = dd.DateID JOIN Dim_Genre dg ON f.GenreID = dg.GenreID GROUP BY dd.[year], dg.Name ); SELECT * FROM RPSalesPerYearPerGenreDW;

Query 4) USE ChinookDW; CREATE VIEW RPTrackSoldPerArtistPerYearTop10DW AS WITH top10Artiesten(artistID) AS ( SELECT TOP(10) da.Name FROM Fact_Sales f JOIN Dim_Artist da ON f.ArtistID = da.ArtistID GROUP BY da.Name ORDER BY SUM(f.Quantity) DESC, da.Name ASC) SELECT da.Name AS 'Name', dd.[year] AS 'Year', SUM(f.Quantity) AS 'Sales' FROM Fact_Sales f JOIN Dim_Artist da ON f.ArtistID = da.ArtistID JOIN Dim_Date dd ON f.DateID = dd.DateID GROUP BY da.Name, dd.[year] HAVING (da.Name IN (SELECT top10Artiesten.artistID FROM top10Artiesten)); SELECT * FROM RPTrackSoldPerArtistPerYearTop10DW;

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 9

Query 6) USE ChinookDW; CREATE VIEW RPGrowthByCountryDW AS WITH LastYearTotal(country, sales) AS ( SELECT dcc.Country, SUM(SalesAmount) FROM Fact_Sales fs JOIN [Dim_Customer-Country] dcc ON fs.CustomerId = dcc.CustomerId JOIN Dim_Date dd ON fs.DateID = dd.DateID WHERE (dd.Year = year(getDate()) - 1) AND (dcc.Region LIKE '%Europe%') GROUP BY dcc.Country ), TwoYearsAgoTotal(country, sales) AS ( SELECT dcc.Country, SUM(SalesAmount) FROM Fact_Sales fs JOIN [Dim_Customer-Country] dcc ON fs.CustomerId = dcc.CustomerId JOIN Dim_Date dd ON fs.DateID = dd.DateID WHERE (dd.Year = year(getDate()) - 2) AND (dcc.Region LIKE '%Europe%') GROUP BY dcc.Country ) SELECT ISNULL(l.country, t.country) AS 'Country', CAST( CASE ISNULL(t.sales, 0) WHEN 0 THEN 1999 ELSE ((ISNULL(l.sales, 0) - t.sales) / t.sales * 100) END AS int) AS 'Growth' FROM LastYearTotal l FULL OUTER JOIN TwoYearsAgoTotal t ON l.country = t.country SELECT * FROM RPGrowthByCountryDW;

Opdracht 10: Query result

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 10

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 11

Opdracht 11: Schedule the package

Opdracht 12: PowerBI service report

Arno Van Nieuwenhove, Illias Dkhissi, Jordi Perreman, Kimberly De Clerq, Slav Mitov, Souhaib Akrouchi

GROEP 2 DELIVERABLES 12

ETL

Control flowchart

Slowly changing dimension