0% found this document useful (0 votes)
6 views

rootCourseAssessments-DAG2-courseAssessments_Exercise 3 - SQL Funamentals (SQL CASE Statements)

The document provides a series of SQL exercises focused on using CASE statements to classify data from various tables, including products, orders, employees, students, deliveries, tickets, attendance, products inventory, classes, and payments. Each exercise includes specific instructions for output columns and categorization criteria. The final submissions are to be scanned and emailed by a specified deadline.

Uploaded by

plaatjies.ipele
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

rootCourseAssessments-DAG2-courseAssessments_Exercise 3 - SQL Funamentals (SQL CASE Statements)

The document provides a series of SQL exercises focused on using CASE statements to classify data from various tables, including products, orders, employees, students, deliveries, tickets, attendance, products inventory, classes, and payments. Each exercise includes specific instructions for output columns and categorization criteria. The final submissions are to be scanned and emailed by a specified deadline.

Uploaded by

plaatjies.ipele
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

BrightLight Tutorials – Data Analytics

SQL Fundamentals

Exercise 3: SQL CASE Statements

Instructions:

1. Write your answers on paper using a pen.


2. For each query, draw a table showing the final output (the result set).
3. In your SELECT statements, choose relevant columns to display, unless specified.
4. After completing all questions, scan your work into a PDF.
5. Email your PDF to: [email protected]
6. Submission Deadline: 21 April 2025, 23:59

Questions

1. Table: products
product_id product_name price

1 Laptop 1200.00

2 Phone 800.00

3 Keyboard 45.00

4 Monitor 300.00

5 Mouse 25.00

Question:

Classify each product by price:

● 'Expensive' if price > 1000


● 'Mid-range' if price between 100 and 1000
● 'Budget' if price < 100

Expected Output Columns:

● product_name
● price
● price_category
2. Table: orders
order_id customer_name amount

1 Alice 150.00

2 Bob 560.00

3 Charlie 999.99

4 Diana 45.50

5 Ethan 1200.00

Question:

Label each order:

● 'High Value' for orders ≥ 1000


● 'Medium Value' for 500–999.99
● 'Low Value' for orders < 500

Expected Output Columns:

● customer_name
● amount
● order_value_category
3. Table: employees
emp_id emp_name department salary

1 John IT 85000

2 Sara HR 60000

3 Mark IT 75000

4 Lucy Finance 95000

5 Tom HR 55000

Question:

Categorize employee position:

● If in 'IT' and salary > 80000 → 'Senior IT'


● If in 'HR' and salary > 55000 → 'Experienced HR'
● Otherwise → 'Staff'

Expected Output Columns:

● emp_name
● department
● salary
● position_level
4. Table: students
student_i student_name score
d
1 Anna 92

2 Ben 76

3 Cara 59

4 David 83

5 Ella 68

Question:

Assign a letter grade:

● ≥ 90: 'A'
● 80–89: 'B'
● 70–79: 'C'
● 60–69: 'D'
● < 60: 'F'

Expected Output Columns:

● student_name
● score
● grade
5. Table: deliveries
delivery_id delivery_time_minutes

1 45

2 80

3 30

4 65

5 100

Question:

Label delivery performance:

● ≤ 30 mins: 'Fast'
● 31–60 mins: 'On Time'
● 60 mins: 'Late'

Expected Output Columns:

● delivery_id
● delivery_time_minutes
● performance
6. Table: tickets
ticket_id issue_type priority

1 Login issue 1

2 Server down 3

3 Slow system 2

4 Email error 2

5 Password 1
reset

Question:

Convert priority to labels:

● 3 → 'High'
● 2 → 'Medium'
● 1 → 'Low'

Expected Output Columns:

● issue_type
● priority
● priority_label
7. Table: attendance
student_i days_presen total_day
d t s
1 45 50

2 30 50

3 48 50

4 25 50

5 50 50

Question:

Calculate attendance % and classify:

● ≥ 90% → 'Excellent'
● 75–89% → 'Good'
● < 75% → 'Needs Improvement'

Expected Output Columns:

● student_id
● attendance_percentage
● attendance_status
8. Table: products_inventory
product_id stock_qty

1 5

2 0

3 25

4 10

5 3

Question:

Label stock status:

● 0 → 'Out of Stock'
● 1–5 → 'Low Stock'
● 5 → 'In Stock'

Expected Output Columns:

● product_id
● stock_qty
● stock_status
9. Table: classes
class_id subject enrolled_students

1 Math 30

2 English 25

3 Science 15

4 Art 5

5 History 20

Question:

Classify by size:

● ≥ 25 → 'Large'
● 10–24 → 'Medium'
● < 10 → 'Small'

Expected Output Columns:

● subject
● enrolled_students
● class_size_category
10. Table: payments
payment_id amount payment_method

1 50.00 Card

2 200.00 Cash

3 150.00 Card

4 75.00 PayPal

5 300.00 Cash

Question:

Apply discount flag:

● If payment_method = 'Cash' and amount ≥ 200 → 'Eligible for Discount'


● Otherwise → 'Not Eligible'

Expected Output Columns:

● payment_id
● payment_method
● amount
● discount_eligibility

You might also like