0% found this document useful (0 votes)
8 views4 pages

COMP238-Lab-Manual-6 - 34002 Assignment 2

The document outlines a lab session for a Database Management System course at Minhaj University, focusing on set operations and aggregate functions. It includes tasks such as creating tables for bikes and cars, performing union, intersection, and except operations, as well as counting records and calculating minimum, maximum, and average values. The document provides SQL queries for each task to facilitate learning and practice.

Uploaded by

aqeelat36
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)
8 views4 pages

COMP238-Lab-Manual-6 - 34002 Assignment 2

The document outlines a lab session for a Database Management System course at Minhaj University, focusing on set operations and aggregate functions. It includes tasks such as creating tables for bikes and cars, performing union, intersection, and except operations, as well as counting records and calculating minimum, maximum, and average values. The document provides SQL queries for each task to facilitate learning and practice.

Uploaded by

aqeelat36
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/ 4

Minhaj University, Lahore Campus

Department of Computer Sciences


Course: Database Management System Lab Date:

Course Code: CSL 220 Max Marks:

Lab Engineer: Anas Abdul


Faculty’s Name:
Wahid

Name: Aqeela Tahir Enroll No: 2023fmulbscs032

OBJECTIVE:
The objective of this lab session is to learn Set operations Union, intersection, Except
and Aggregate Functions
Create this table Bikes and insert 5 Create this table Cars and insert 5
records records

create table bikes create table cars (


(bikes varchar (15), car varchar (15),
model varchar (15), model varchar (15),
Yearr varchar (15), Yearr varchar (15),
colour varchar (15), colour varchar (15),
owner_name varchar (15), owner_name varchar (15),
owner_id int ); owner_id int );

Task 1
1. Find union of car and owner_name
from both tables SELECT car AS vehicle, owner_name FROM
cars
UNION
SELECT bikes AS vehicle, owner_name FROM
bikes;

2. Practice another union statement.


SELECT model FROM cars
UNION
SELECT model FROM bikes;

3. How to find distinct values using SELECT colour FROM cars


union statement UNION
SELECT colour FROM bikes;

4. Practice another union all statement

SELECT colour FROM cars


UNION ALL
SELECT colour FROM bikes;
-- UNION ALL includes duplicates

Task 2
1.Show only 1st row of table bikes

SELECT * FROM bikes


LIMIT 1;

2.Show 1st three rows in table car

SELECT * FROM cars


LIMIT 3;

3.Practice except operator


SELECT model FROM cars
EXCEPT
SELECT model FROM bikes;
-- Shows models in cars but not in bikes

4.Find intersection of car and bikes from


both tables

SELECT car AS vehicle FROM cars


INTERSECT
SELECT bikes AS vehicle FROM bikes;

Task 3
1. Show the Count of total numbers of
records in table cars
SELECT COUNT(*) FROM cars;
2. Count total numbers of records in
table bikes SELECT COUNT(*) FROM bikes;

3. Retrieve the total Count number of


cars having colour grey
SELECT COUNT(*) FROM cars WHERE colour
= 'Grey';

4. Show the total Count number of cars


having model 2011
SELECT COUNT(*) FROM cars WHERE Yearr
= '2011';

5. Retrieve minimum year in cars

SELECT MIN(CAST(Yearr AS INT)) FROM


cars;

6. Display minimum model from the


table bikes
SELECT MIN(CAST(Yearr AS INT)) FROM
cars;

Task 4
1. Show maximum year in bikes

SELECT MAX(CAST(Yearr AS INT)) FROM


bikes;

2. Display maximum model from the


table cars
SELECT MAX(model) FROM cars;

3. Retrieve average owner_id in cars

SELECT AVG(owner_id) FROM cars;

4. Show average model from the table


bikes
SELECT AVG(CAST(Yearr AS INT)) FROM
bikes;
5. Find sum of year in cars SELECT SUM(CAST(Yearr AS INT)) FROM
cars;

=====================================================================================

You might also like