0% found this document useful (0 votes)
11 views8 pages

DBMS Lab 03 (Bukc)

The document outlines a lab experiment consisting of ten SQL tasks related to database management, focusing on querying employee, product, and customer data. Each task includes a specific objective and a corresponding SQL solution. The tasks involve filtering, counting, and aggregating data from various tables to derive insights.
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)
11 views8 pages

DBMS Lab 03 (Bukc)

The document outlines a lab experiment consisting of ten SQL tasks related to database management, focusing on querying employee, product, and customer data. Each task includes a specific objective and a corresponding SQL solution. The tasks involve filtering, counting, and aggregating data from various tables to derive insights.
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/ 8

Bahria University,

Karachi Campus

LAB EXPERIMENT NO.


_03_
LIST OF TASKS
TASK NO OBJECTIVE
01 Display first and last names of all employees whose names does not contain “a” in their names in
ascending order. (Employees Table)

02 Retrieve the product names and their corresponding quantities in stock for products with UnitsInStock
below 50. Also sort the list by UnitsInStock in descending order. (Table: Products)

03 From customers table, count all customers in each region whose contactTitle does not contain manager and
region is not null. (Table: Customers)

04 Write a query to display the number of ContactName with same ContactTitle. Sort contact title in
ascending order. (Table: Customers)

05 List the employee id, names and their hire dates for employees hired after the year 1992. Order the results
by hire date in ascending order. (Table: Employees)

06 Display the highest, lowest, sum and average UnitPrice of each Category, where highest UnitPrice lies in
the range of 100$ to 500$. Label column as CategoryId, Maximum, Minimum, Sum and Average,
respectively. (Table: Products)

07 How many people are in each unique city in the employee table that have more than one person in the city?
Select the city and display the number of how many people are in each if it's greater than 1.(Table:
Employees)

08 Find the product name, maximum price and minimum price of each product having maximum price greater
than 20.00 $. Order by maximum price. (Tabel: Products)

09 Write a query to list no of customers with same ContactTitle if No of customers is greater than 5.
However, their ContactTitle does not contain Manager. Order by contact title in descending order (Table:
Customers)

10 Retrieve the count of products in each category where the unit price is less than 30 dollars. Label the
columns as CategoryID and ProductCount. (Tables: Products)

Submitted On:
Date: 25/02/2025
[Lab no. 03] [Database Management
System Lab]
[Aggregate Functions in
SQL]

Task No. 01:


Solution:
select FirstName, LastName FROM Employees WHERE FirstName NOT LIKE '%a%' AND LastName NOT LIKE '%a%' ORDER
BY FirstName, LastName;

Output:

Task No. 02:


Solution:
select ProductName, UnitsInStock FROM Products WHERE UnitsInStock < 50 ORDER BY UnitsInStock DESC;

Output:

Muhammad Sufiyan Aasim 02-131222-019


[Lab no. 03] [Database Management
System Lab]
[Aggregate Functions in
SQL]

Task No. 03:


Solution:
select Region, COUNT(*) AS CustomerCount FROM Customers WHERE ContactTitle NOT LIKE '%Manager%' AND Region
IS NOT NULL GROUP BY Region;

Output:

Task No. 04:


Solution:
select ContactTitle, COUNT(ContactName) AS ContactCount FROM Customers GROUP BY ContactTitle ORDER BY
ContactTitle ASC;

Muhammad Sufiyan Aasim 02-131222-019


[Lab no. 03] [Database Management
System Lab]
[Aggregate Functions in
SQL]
Output:

Task No. 05:


Solution:
select EmployeeID, FirstName, LastName, HireDate FROM Employees WHERE YEAR(HireDate) > 1992 ORDER BY
HireDate ASC;

Output:

Task No. 06:


Solution:

Muhammad Sufiyan Aasim 02-131222-019


[Lab no. 03] [Database Management
System Lab]
[Aggregate Functions in
SQL]
select CategoryID, MAX(UnitPrice) AS Maximum, MIN(UnitPrice) AS Minimum, SUM(UnitPrice) AS Sum, AVG(UnitPrice)
AS Average FROM Products GROUP BY CategoryID HAVING MAX(UnitPrice) BETWEEN 100 AND 500;

Output:

Task No. 07:


Solution:
select City, COUNT(*) AS EmployeeCount FROM Employees GROUP BY City HAVING COUNT(*) > 1;

Output:

Task No. 08:


Solution:
Muhammad Sufiyan Aasim 02-131222-019
[Lab no. 03] [Database Management
System Lab]
[Aggregate Functions in
SQL]
select ProductName, MAX(UnitPrice) AS MaxPrice, MIN(UnitPrice) AS MinPrice FROM Products GROUP BY ProductName
HAVING MAX(UnitPrice) > 20 ORDER BY MaxPrice;

Output:

Task No. 09:


Solution:
select ContactTitle, COUNT(*) AS CustomerCount FROM Customers WHERE ContactTitle NOT LIKE '%Manager%' GROUP
BY ContactTitle HAVING COUNT(*) > 5 ORDER BY ContactTitle DESC;

Output:

Muhammad Sufiyan Aasim 02-131222-019


[Lab no. 03] [Database Management
System Lab]
[Aggregate Functions in
SQL]
Task No. 10:
Solution:
select CategoryID, COUNT(*) AS ProductCount FROM Products WHERE UnitPrice < 30 GROUP BY CategoryID;

Output:

Muhammad Sufiyan Aasim 02-131222-019

You might also like