3. SQL for Data Preparation
Activity 3.01: Building a Sales Model Using SQL Techniques
Solution:
- Open
pgAdmin, connect to thesqldadatabase, and open the SQL query editor. - Use
INNER JOINto join thecustomerstable to thesalestable:FROM sales s JOIN customers c ON s.customer_id = c.customer_id
Note that the SQL in Steps 2, 3, and 4 is not complete SQL that you can run in pgAdmin. They are part of the FROM…JOIN clause on which the full SELECT statement will be built. They are created to guide you through the process of forming a complex dataset using JOIN. If you want to test the SQL, you can make it complete by adding SELECT * at the start.
- Use
INNER JOINto join theproductstable to thesalestable:FROM sales s JOIN customers c ON s.customer_id = c.customer_id JOIN products p ON s.product_id = p.product_id
- Use
LEFT JOINto join thedealershipstable (right table) to thesalestable (left table):FROM sales s LEFT JOIN dealerships...