Skip to content

Commit 65e0ea7

Browse files
authored
Add SQL queries for retrieving, filtering, and sorting data
Added SQL queries for the following tasks: - Retrieving specific columns (checkNumber, paymentDate, amount) from the payments table. - Filtering and sorting orders by status 'In Process' and orderDate. - Displaying employee details for the job title 'Sales Rep', ordered by employeeNumber. - Fetching all columns from the offices table. - Sorting products by buyPrice and limiting results to 5 records.
1 parent f62d1f4 commit 65e0ea7

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

answers.sql

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
11
-- 1. Retrieve checkNumber, paymentDate, and amount from the payments table
2-
-- This query selects specific columns from the payments table: checkNumber, paymentDate, and amount.
2+
-- In this query, we are selecting the columns 'checkNumber', 'paymentDate', and 'amount' from the 'payments' table.
3+
-- These columns store information about payment transactions, such as the check number, the date of payment, and the amount paid.
34

45
SELECT checkNumber, paymentDate, amount
56
FROM payments;
67

8+
79
-- 2. Retrieve orderDate, requiredDate, and status of orders with 'In Process' status
8-
-- The query filters orders with the status 'In Process' and sorts them in descending order of orderDate.
10+
-- This query is filtering orders with the status 'In Process'.
11+
-- The 'status' column indicates the current state of the order. We then sort the results by 'orderDate' in descending order
12+
-- to display the most recent orders first.
913

1014
SELECT orderDate, requiredDate, status
1115
FROM orders
12-
WHERE status = 'In Process'
13-
ORDER BY orderDate DESC;
16+
WHERE status = 'In Process' -- Filter only orders that are still 'In Process'
17+
ORDER BY orderDate DESC; -- Sort results by orderDate in descending order
18+
1419

1520
-- 3. Retrieve firstName, lastName, and email of employees with the job title 'Sales Rep'
16-
-- The query filters employees with the job title 'Sales Rep' and orders the results by employeeNumber in descending order.
21+
-- This query filters employees based on their job title ('Sales Rep').
22+
-- We are interested in employees working in sales, and we order the results by 'employeeNumber' in descending order,
23+
-- which helps to see the most recently added employees first.
1724

1825
SELECT firstName, lastName, email
1926
FROM employees
20-
WHERE jobTitle = 'Sales Rep'
21-
ORDER BY employeeNumber DESC;
27+
WHERE jobTitle = 'Sales Rep' -- Filter employees who have 'Sales Rep' as their job title
28+
ORDER BY employeeNumber DESC; -- Sort results by employeeNumber in descending order
29+
2230

2331
-- 4. Retrieve all columns and records from the offices table
24-
-- This query selects all columns and records from the offices table without applying any filters.
32+
-- This query retrieves all columns (*) and all records from the 'offices' table.
33+
-- The 'offices' table contains information about the company's office locations, such as city, country, and phone number.
34+
35+
SELECT *
36+
FROM offices; -- Retrieve all columns from the offices table
2537

26-
SELECT *
27-
FROM offices;
2838

2939
-- 5. Retrieve productName and quantityInStock from the products table
30-
-- The query sorts the results by buyPrice in ascending order and limits the output to 5 records.
40+
-- In this query, we retrieve the 'productName' and 'quantityInStock' from the 'products' table.
41+
-- We are also sorting the results by 'buyPrice' in ascending order, which helps to see the cheapest products first.
42+
-- Finally, we limit the output to only the first 5 records.
3143

3244
SELECT productName, quantityInStock
3345
FROM products
34-
ORDER BY buyPrice ASC
35-
LIMIT 5;
46+
ORDER BY buyPrice ASC -- Sort results by 'buyPrice' in ascending order
47+
LIMIT 5; -- Limit the result to only the first 5 records

0 commit comments

Comments
 (0)