Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
-- ============================================================

-- Write your query below:

SELECT first_name, last_name, city, phone
FROM sales.customers
WHERE state = 'CA'
AND phone IS NOT NULL;



Expand All @@ -27,7 +30,10 @@
-- ============================================================

-- Write your query below:

SELECT product_id, product_name, model_year, list_price
FROM production.products
ORDER BY model_year DESC,
list_price ASC;



Expand All @@ -41,11 +47,15 @@
-- ============================================================

-- Part a:

SELECT TOP 5 product_name,list_price
FROM production.products
ORDER BY list_price DESC;

-- Part b:


SELECT TOP 5 PERCENT *
FROM production.products
ORDER BY list_price ASC;


-- ============================================================
Expand All @@ -59,14 +69,27 @@
-- ============================================================

-- Page 1:

SELECT *
FROM production.products
ORDER BY list_price DESC
OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY;

-- Page 2:

SELECT *
FROM production.products
ORDER BY list_price DESC
OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;


-- Page 3:


SELECT *
FROM production.products
ORDER BY list_price DESC
OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY;



-- ============================================================
Expand All @@ -81,15 +104,25 @@
-- ============================================================

-- Part a:

SELECT DISTINCT state
FROM sales.customers
ORDER BY state ASC;

-- Part b:

-- b) Unique combinations of state and city
SELECT DISTINCT state,
city
FROM sales.customers
ORDER BY state ASC,
city ASC;

-- Part c:

-- c) Number of unique model years


SELECT DISTINCT model_year
FROM production.products
ORDER BY model_year;

-- ============================================================
-- Question 6 — Logical Operators (AND / OR)
Expand All @@ -102,4 +135,9 @@
-- Hint: use parentheses to control the order of evaluation.
-- ============================================================

-- Write your query below:
-- WritSELECT product_id,
SELECT product_id, product_name, brand_id, category_id, list_price
FROM production.products
WHERE list_price BETWEEN 500 AND 1500
AND (model_year = 2019 OR model_year = 2020)
ORDER BY list_price ASC;