-1

I am new to using SQL Server. I have an assignment, and the lecturer is not showing us how to use the tools he wants the assignment to be completed with.

I am trying to come up with a query that will insert the primary key of 3 dimension tables into as well as trying to insert data from the source data in another table.

The source data is a data set of 10000+ Apps on the Google Play Store.

See below for my table and what I need

DimContentRating - there are 6 content ratings

ContentRatingID(PK)   Content Rating
---------------       --------------
1                     Everyone
2                     Teen

DimCategory - there are 34 categories

CategoryID(PK)   Category
----------       --------
1                Education
2                Finance

DimInstalls - there are many ranges of installs

InstallID(PK)  Installs
----------     --------
1              10000+
2              100000+

googleplaystore - the table with the 10000+ records and original data

App       Category  Rating  Reviews  Installs  Price  Content_Rating  
---       --------  ------  ------   --------  -----  --------------
GMAT 
Question  Education  4.2     240      10000+    Free    Everyone
Bank

Ace Elite Finance    4.1     2898     100000+   Free    Everyone

How I need it to look

AppFact - The table that needs the tables above to be broken down from the above tables and inserted using links from Foreign Keys

AppFactID    Category  Rating  Reviews  Installs  Price  Content_Rating  
---------    --------  ------  ------   --------  -----  --------------
1              1        4.2     240       1        Free       1
2              2        4.1     2898       2       Free       1

I do apologize for not having a query that I tried writing to get it to work but I have not been shown much at all about SQL Server and so the best I know is general queries. What I do know is I need to use the below as well as possible inner joins?

INSERT INTO AppFact(...) 
    SELECT ... 
    FROM ... 

Am I on the right track?

halfer
  • 19,824
  • 17
  • 99
  • 186
Carl O'Beirne
  • 309
  • 1
  • 6
  • 17
  • " I need to use the below as well as possible inner joins? INSERT INTO AppFact(...) SELECT ... FROM ... " This appears to be the answer to your question, so what are you really asking? – Tab Alleman Dec 10 '18 at 16:27
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Dec 13 '18 at 19:52

1 Answers1

1

Assuming you already create the table AppFact with PK AppFactID, the query you're looking for is:

INSERT INTO AppFact (Category, Rating, Reviews, Installs, Price, Content_Rating)
SELECT c.CategoryID, a.Rating, a.Reviews, i.Installs, a.Price, r.ContentRatingID
FROM googleplaystore a
    INNER JOIN DimContentRating r ON a.Content_Rating = r.Content_Rating
    INNER JOIN DimCategory c ON a.Category = c.Category
    INNER JOIN DimInstalls i ON a.Installs = i.Installs

You should take a look to JOINs in SQL Server