|
1 | 1 | -- 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. |
3 | 4 |
|
4 | 5 | SELECT checkNumber, paymentDate, amount |
5 | 6 | FROM payments; |
6 | 7 |
|
| 8 | + |
7 | 9 | -- 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. |
9 | 13 |
|
10 | 14 | SELECT orderDate, requiredDate, status |
11 | 15 | 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 | + |
14 | 19 |
|
15 | 20 | -- 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. |
17 | 24 |
|
18 | 25 | SELECT firstName, lastName, email |
19 | 26 | 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 | + |
22 | 30 |
|
23 | 31 | -- 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 |
25 | 37 |
|
26 | | -SELECT * |
27 | | -FROM offices; |
28 | 38 |
|
29 | 39 | -- 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. |
31 | 43 |
|
32 | 44 | SELECT productName, quantityInStock |
33 | 45 | 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