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

Lab3 Report

The document outlines a report on SQL tasks related to a Customer Management System, detailing various tasks such as creating tables, inserting data, and executing queries to analyze customer information. Key tasks include displaying the top users, counting customers from specific locations, and formatting customer names in different ways. The report is authored by Doumbia Youssouf and dated March 24, 2025.

Uploaded by

mansoureh225
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)
5 views8 pages

Lab3 Report

The document outlines a report on SQL tasks related to a Customer Management System, detailing various tasks such as creating tables, inserting data, and executing queries to analyze customer information. Key tasks include displaying the top users, counting customers from specific locations, and formatting customer names in different ways. The report is authored by Doumbia Youssouf and dated March 24, 2025.

Uploaded by

mansoureh225
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/ 8

Islamic University of Technology

Relational Database Management System


Lab
CSE 4508

REPORT TITLE

DOUMBIA YOUSSOUF

March 24, 2025


Contents
1 Task 1: Create Tables and Insert Data 2

2 Task 2: Display Top 5 Highest Users 3

3 Task 3: Customers with Lifetime Usage Exceeding Average 4

4 Task 4: Count Customers from Dhaka 4

5 Task 5: Full Name with Prefix 5

6 Task 6: Capitalized Customer Names 5

7 Task 7: Customers with Substring ”an” 5

8 Task 8: Lowercase Customer Names 5

9 Task 9: Uppercase Customer Names 6

10 Task 10: Length of Customer Names 6

11 Task 11: Padded Customer Names 6

12 Task 12: Trimmed Customer Names 6

13 Task 13: First 5 Characters of Customer Names 7

14 Task 14: Count Customers by Division 7

1
Customer Management System SQL Tasks

1 Task 1: Create Tables and Insert Data


The following SQL commands create the necessary tables and populate them
with initial data for the customer management system.
1 CREATE TABLE Customers (
2 Customer_ID NUMBER PRIMARY KEY ,
3 Customer_Name VARCHAR2 (100) ,
4 Date_of_Birth DATE ,
5 Address_ID NUMBER ,
6 Subscription_ID NUMBER
7 );
8

9 CREATE TABLE Addresses (


10 Address_ID NUMBER PRIMARY KEY ,
11 Division VARCHAR2 (50) ,
12 District VARCHAR2 (50)
13 );
14

15 CREATE TABLE Subscriptions (


16 Subscription_ID NUMBER PRIMARY KEY ,
17 Subscriber_Type VARCHAR2 (10) ,
18 Subscriber_Level VARCHAR2 (10) ,
19 Lifetime_Usage NUMBER
20 );
21

22 INSERT INTO Addresses VALUES (1 , ’ Dhaka ’ , ’ Dhaka ’) ;


23 INSERT INTO Addresses VALUES (2 , ’ Khulna ’ , ’ Jessore ’
);

2
24 INSERT INTO Addresses VALUES (3 , ’ Chittagong ’ , ’
Comilla ’) ;
25 INSERT INTO Addresses VALUES (4 , ’ Dhaka ’ , ’ Gazipur ’)
;
26 INSERT INTO Addresses VALUES (5 , ’ Sylhet ’ , ’ Sylhet ’)
;
27

28 INSERT INTO Subscriptions VALUES (1 , ’ Prepaid ’ , ’


Silver ’ , 5000) ;
29 INSERT INTO Subscriptions VALUES (2 , ’ Postpaid ’ , ’
Gold ’ , 20000) ;
30 INSERT INTO Subscriptions VALUES (3 , ’ Prepaid ’ , ’
Bronze ’ , 3000) ;
31 INSERT INTO Subscriptions VALUES (4 , ’ Postpaid ’ , ’
Platinum ’ , 40000) ;
32 INSERT INTO Subscriptions VALUES (5 , ’ Prepaid ’ , ’
Silver ’ , 7000) ;
33

34 INSERT INTO Customers VALUES (1 , ’ john Doe ’ ,


TO_DATE ( ’ 1990 -05 -10 ’ , ’ YYYY - MM - DD ’) , 1 , 1) ;
35 INSERT INTO Customers VALUES (2 , ’ Jane smith ’ ,
TO_DATE ( ’ 1985 -12 -25 ’ , ’ YYYY - MM - DD ’) , 2 , 2) ;
36 INSERT INTO Customers VALUES (3 , ’ ahmed khan ’ ,
TO_DATE ( ’ 1975 -07 -15 ’ , ’ YYYY - MM - DD ’) , 3 , 3) ;
37 INSERT INTO Customers VALUES (4 , ’ lisa Rahman ’ ,
TO_DATE ( ’ 1992 -03 -09 ’ , ’ YYYY - MM - DD ’) , 4 , 4) ;
38 INSERT INTO Customers VALUES (5 , ’ Samiul Islam ’ ,
TO_DATE ( ’ 1988 -11 -19 ’ , ’ YYYY - MM - DD ’) , 5 , 5) ;

2 Task 2: Display Top 5 Highest Users


This query retrieves the top 5 customers based on their lifetime usage.
1 SELECT C . Customer_Name , C . Customer_ID , S .
Lifetime_Usage
2 FROM Customers C

3
3 JOIN Subscriptions S ON C . Subscription_ID = S .
Subscription_ID
4 ORDER BY S . Lifetime_Usage DESC
5 FETCH FIRST 5 ROWS ONLY ;

3 Task 3: Customers with Lifetime Usage


Exceeding Average
This query lists customers whose lifetime usage exceeds the average of prepaid
users with Silver status.
1 SELECT C . Customer_Name , C . Date_of_Birth , A . District ,
A . Division
2 FROM Customers C
3 JOIN Subscriptions S ON C . Subscription_ID = S .
Subscription_ID
4 JOIN Addresses A ON C . Address_ID = A . Address_ID
5 WHERE S . Lifetime_Usage > (
6 SELECT AVG ( S2 . Lifetime_Usage )
7 FROM Subscriptions S2
8 WHERE S2 . Subscriber_Type = ’ Prepaid ’ AND S2 .
Subscriber_Level = ’ Silver ’
9 );

4 Task 4: Count Customers from Dhaka


This query counts how many customers from the previous query are located
in Dhaka.
1 SELECT COUNT (*)
2 FROM Customers C
3 JOIN Subscriptions S ON C . Subscription_ID = S .
Subscription_ID
4 JOIN Addresses A ON C . Address_ID = A . Address_ID
5 WHERE S . Lifetime_Usage > (
6 SELECT AVG ( S2 . Lifetime_Usage )

4
7 FROM Subscriptions S2
8 WHERE S2 . Subscriber_Type = ’ Prepaid ’ AND S2 .
Subscriber_Level = ’ Silver ’
9 ) AND A . Division = ’ Dhaka ’;

5 Task 5: Full Name with Prefix


This query displays the full name of each customer with the prefix ”Mr./Ms.”
concatenated.
1 SELECT ’ Mr ./ Ms . ’ || Customer_Name AS Full_Name
2 FROM Customers ;

6 Task 6: Capitalized Customer Names


This query retrieves customer names with the first letter of each word capi-
talized.
1 SELECT INITCAP ( Customer_Name ) AS Capitalized_Name
2 FROM Customers ;

7 Task 7: Customers with Substring ”an”


This query finds customers whose names contain the substring ”an” and
returns the position of its appearance.
1 SELECT Customer_Name , INSTR ( Customer_Name , ’ an ’) AS
Position
2 FROM Customers
3 WHERE INSTR ( Customer_Name , ’ an ’) > 0;

8 Task 8: Lowercase Customer Names


This query displays all customer names in lowercase.

5
1 SELECT LOWER ( Customer_Name ) AS Lowercase_Name
2 FROM Customers ;

9 Task 9: Uppercase Customer Names


This query displays all customer names in uppercase.
1 SELECT UPPER ( Customer_Name ) AS Uppercase_Name
2 FROM Customers ;

10 Task 10: Length of Customer Names


This query displays the length of each customer’s name.
1 SELECT Customer_Name , LENGTH ( Customer_Name ) AS
Name_Length
2 FROM Customers ;

11 Task 11: Padded Customer Names


This query pads customer names with asterisks (*) to make the total length
15 characters.
1 SELECT LPAD ( Customer_Name , 15 , ’* ’) AS Padded_Name
2 FROM Customers ;

12 Task 12: Trimmed Customer Names


This query displays customer names after trimming any leading whitespace.
1 SELECT LTRIM ( Customer_Name ) AS Trimmed_Name
2 FROM Customers ;

6
13 Task 13: First 5 Characters of Customer
Names
This query retrieves the first 5 characters of each customer’s name.
1 SELECT SUBSTR ( Customer_Name , 1 , 5) AS
First_Five_Characters
2 FROM Customers ;

14 Task 14: Count Customers by Division


This query counts the number of customers from each division.
1 SELECT A . Division , COUNT (*) AS Customer_Count
2 FROM Customers C
3 JOIN Addresses A ON C . Address_ID = A . Address_ID
4 GROUP BY A . Division ;

You might also like