From 970726bb6936063a569ec09a55ab47f615e82fea Mon Sep 17 00:00:00 2001 From: sheerazalipersonal Date: Sun, 3 May 2026 05:58:38 -0700 Subject: [PATCH] Updated Assignment01 - Querying Sorting Filtering.sql --- ...gnment01 - Querying Sorting Filtering.sql" | 56 ++++++++++++++++--- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git "a/batch-05/Section 1 \342\200\224 SQL/Class01 - Querying Sorting Filtering/Assignment01 - Querying Sorting Filtering.sql" "b/batch-05/Section 1 \342\200\224 SQL/Class01 - Querying Sorting Filtering/Assignment01 - Querying Sorting Filtering.sql" index aee2587..6c06fc9 100644 --- "a/batch-05/Section 1 \342\200\224 SQL/Class01 - Querying Sorting Filtering/Assignment01 - Querying Sorting Filtering.sql" +++ "b/batch-05/Section 1 \342\200\224 SQL/Class01 - Querying Sorting Filtering/Assignment01 - Querying Sorting Filtering.sql" @@ -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; @@ -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; @@ -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; -- ============================================================ @@ -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; + -- ============================================================ @@ -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) @@ -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;