Complete the SQL code to select all columns from the fact table named 'sales'.
SELECT [1] FROM sales;Using * selects all columns from the table.
Complete the SQL code to join the fact table 'sales' with the dimension table 'customers' on the customer ID.
SELECT sales.*, customers.name FROM sales JOIN customers ON sales.customer_id [1] customers.customer_id;The join condition uses the equals sign (=) to match keys between tables.
Fix the error in the SQL code to create a fact table named 'sales_fact' with a primary key 'sale_id'.
CREATE TABLE sales_fact (sale_id INT [1] PRIMARY KEY, amount DECIMAL(10,2));
In SQL, AUTO_INCREMENT is used to auto-generate unique keys in MySQL.
Fill both blanks to create a dimension table 'product_dim' with a surrogate key and product name.
CREATE TABLE product_dim (product_key INT [1] PRIMARY KEY, product_name VARCHAR(100) [2] NOT NULL);
The surrogate key uses AUTO_INCREMENT to generate unique keys. The product name cannot be null, so it uses NOT NULL.
Fill all three blanks to write a SQL query that calculates total sales amount grouped by product category.
SELECT category, SUM([1]) AS total_sales FROM sales_fact JOIN product_dim ON sales_fact.product_key = product_dim.product_key GROUP BY [2] ORDER BY [3] DESC;
The SUM(amount) calculates total sales. Grouping and ordering are done by category and the alias total_sales respectively.