0% found this document useful (0 votes)
61 views5 pages

Lab 04 DBMS

This document introduces Lab #4 on sorting data and set operators in an Introduction to Database Systems course. The lab objectives are to sort rows retrieved by a query and use set operators. It includes 4 tasks - writing SQL queries to: 1) Find employees whose names contain R, A, or N, sorted by ascending salary 2) Find employees earning above 21000 or with phone number fifth character 8, sorted by last name 3) Find salespersons with largest and smallest orders on each date 4) Find salespersons with customer cities matching their own or marked "NO MATCH", sorted by name

Uploaded by

FARAZ AHMED
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)
61 views5 pages

Lab 04 DBMS

This document introduces Lab #4 on sorting data and set operators in an Introduction to Database Systems course. The lab objectives are to sort rows retrieved by a query and use set operators. It includes 4 tasks - writing SQL queries to: 1) Find employees whose names contain R, A, or N, sorted by ascending salary 2) Find employees earning above 21000 or with phone number fifth character 8, sorted by last name 3) Find salespersons with largest and smallest orders on each date 4) Find salespersons with customer cities matching their own or marked "NO MATCH", sorted by name

Uploaded by

FARAZ AHMED
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/ 5

Introduction to Database Systems (SWE-209L) SSUET/QR/114

Lab # 4: Sorting Data, Set Operators


LAB # 4

SORTING DATA, SET OPERATORS


OBJECTIVE: Sort the rows that are retrieved by a query and use SET Operators.
LAB TASKS:

Employees(employee_id, first_name, last_name, email, phone_number, hire_date, job_id,


salary, commission_pct, manager_id, department_id)

1. From the following schema, write a SQL query to find those employees whose first
name contains the letters R, A, or N. Sort the result-set in ascending order by salary.
Return all fields.

Query:

SYED TAYYAB RAZA ZAIDI (2020-SE-272) 27


Introduction to Database Systems (SWE-209L) SSUET/QR/114

Lab # 4: Sorting Data, Set Operators

Output:

2. From the following schema, write a SQL query to find those employees who earn
above 21000 or the fifth character in their phone number is 8.. Sort the result-set in
ascending order by last name. Return full name (first name and last name), hire date,
commission percentage, email, and telephone separated by '-', and salary.

Query:

Output:

SYED TAYYAB RAZA ZAIDI (2020-SE-272) 28


Introduction to Database Systems (SWE-209L) SSUET/QR/114

Lab # 4: Sorting Data, Set Operators

Orders(ord_no, purch_amt, ord_date, customer_id, salesman_id)


Salesman (salesman_id, name, city, commission)
Customer (customer_id, cust_name, city, grade, salesman_id)

SYED TAYYAB RAZA ZAIDI (2020-SE-272) 29


Introduction to Database Systems (SWE-209L) SSUET/QR/114

Lab # 4: Sorting Data, Set Operators

3. From the following table, write a SQL query to find those salespersons generated
the largest and smallest orders on each date. Return salesperson ID, name, order no.,
highest on/ lowest on, order date.

QUERY:

OUTPUT:

SYED TAYYAB RAZA ZAIDI (2020-SE-272) 30


Introduction to Database Systems (SWE-209L) SSUET/QR/114

Lab # 4: Sorting Data, Set Operators

4. From the following tables, write a SQL query to find those salespersons who have
same cities where customer lives as well as do not have customers in their cities and
indicate it by ‘NO MATCH’. Sort the result set on 2nd column (i.e. name) in
descending order. Return salesperson ID, name, customer name, commission.

QUERY:

OUTPUT:

SYED TAYYAB RAZA ZAIDI (2020-SE-272) 31

You might also like