0% found this document useful (0 votes)
51 views6 pages

Student Name: Abdulaziz Bakhsh Student ID: 1543123 Database Lab 4

This document contains the details of a student's database lab assignment. It includes 3 lab activities with multiple questions in each activity asking the student to write SQL statements to query a database for information like total purchase amount, average purchase amount, number of salesmen, highest purchase amounts for customers, and more. It also includes 4 overview questions at the end asking the student to write SQL statements to display employee details, current date, formatted employee names, and salary statistics. The student has provided the requested SQL code for each question.

Uploaded by

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

Student Name: Abdulaziz Bakhsh Student ID: 1543123 Database Lab 4

This document contains the details of a student's database lab assignment. It includes 3 lab activities with multiple questions in each activity asking the student to write SQL statements to query a database for information like total purchase amount, average purchase amount, number of salesmen, highest purchase amounts for customers, and more. It also includes 4 overview questions at the end asking the student to write SQL statements to display employee details, current date, formatted employee names, and salary statistics. The student has provided the requested SQL code for each question.

Uploaded by

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

Student Name : Abdulaziz Bakhsh

Student ID : 1543123

Database Lab 4

Lab. Activity – 01:

Q : Write a SQL statement to find the total purchase amount of all orders.
Code : SELECT SUM (purch_amt)

FROM orders;

Q : Write a SQL statement to find the average purchase amount of all orders.
Code : SELECT AVG (purch_amt)

FROM orders;
Q : Write a SQL statement to find the number of salesmen currently listing for all of their customers.
Code : SELECT COUNT (DISTINCT salesman_id)

FROM orders;
Lab. Activity – 02:

Q : Write a SQL statement to find the highest purchase amount ordered by the each customer on a
particular date with their ID, order date and highest purchase amount.
Code : SELECT customer_id,ord_date,MAX(purch_amt)

FROM orders

GROUP BY customer_id,ord_date;

Q : Write a SQL statement to find the highest purchase amount ordered by the each customer with their
ID and highest purchase amount.
Code : SELECT customer_id,MAX(purch_amt)

FROM orders

GROUP BY customer_id;
Lab. Activity – 03:

Q : Write a SQL statement to find the highest purchase amount with their ID and order date, for only
those customers who have highest purchase amount in a day is more than 2000.
Code : SELECT customer_id,ord_date,MAX(purch_amt)

FROM orders

GROUP BY customer_id,ord_date

HAVING MAX(purch_amt) > 2000;

Q : Write a SQL statement to find the highest purchase amount with their ID and order date, for those
customers who have a higher purchase amount in a day is within the range 2000 and 6000.
Code : SELECT customer_id,ord_date,MAX(purch_amt)

FROM orders

GROUP BY customer_id,ord_date

HAVING MAX(purch_amt) BETWEEN 2000 AND 6000;


Practice Overview Questions
Q1: The HR department needs a report to display the employee number, last name, salary, and salary
increased by 15.5% (expressed as a whole number) for each employee. Label the column New Salary.

Code: select employee_id, last_name, salary, salary+(salary*15.5/100) "New


Salary"
from employees;

Q2: Write a query to display the current date. Label the column Date
Code: SELECT sysdate "Date"
FROM dual;
Q3: Write a query that displays the last name (with the first letter uppercase and all other letters
lowercase) and the length of the last name for all employees whose name starts with the letters J, A, or
M. Give each column an appropriate label. Sort the results by the employees’ last names.

Code: select initcap(last_name) "Name", length(last_name) "Length of Name"


from employees
where last_name like 'J%' or last_name like 'A%' or last_name like 'M%'
order by last_name;

Q4: Find the highest, lowest, sum, and average salary of all employees. Label the columns Maximum,
Minimum, Sum, and Average, respectively. Round your results to the nearest whole number.

Code: SELECT MAX(SALARY) Maximum, MIN(SALARY) Minimum, SUM(SALARY)


Sum, AVG(SALARY) Average
FROM EMPLOYEES;

You might also like