PDC - Lab 04 - Ece
PDC - Lab 04 - Ece
EXPERIMENT NO. 4
Student Name: ASNAN KHAN, RAYAN SALEH Reg. No: 210296, 210293
Objective:
LAB ASSESSMENT:
Date: Signature:
AIR UNIVERISTY, ISLAMABAD
Department of Electrical & Computer Engineering
DATABASE - LAB
Lab 04 Tasks:
TABLE:
CODE:
OUTPUT:
1
AIR UNIVERISTY, ISLAMABAD
Department of Electrical & Computer Engineering
Task 1:
Calculate the number of records for the 3rd, 4th and 5th column.
Find distinct number of records for the Course Code=1002 as Total.
Find number of students registered for the course DIP as Total Courses
CODE:
--task#1.1
--task#1.2
SELECT COUNT(DISTINCT Reg_No) AS Total FROM studentss WHERE Course_Code =
1002;
--task#1.3
SELECT COUNT(*) AS Total_Courses FROM studentss WHERE Courses = 'DIP';
OUTPUT:
Task 2:
Convert the text valued fields in the above table to the lower case and upper case
alphabets.
CODE:
--task#2
SELECT
LOWER(FName) AS FName_Lowercase,
LOWER(Courses) AS Courses_Lowercase,
LOWER(Offered_By) AS Offered_By_Lowercase
FROM studentss;
2
AIR UNIVERISTY, ISLAMABAD
Department of Electrical & Computer Engineering
SELECT
UPPER(FName) AS FName_Uppercase,
UPPER(Courses) AS Courses_Uppercase,
UPPER(Offered_By) AS Offered_By_Uppercase
FROM studentss;
OUTPUT:
Task 3:
Using GROUP BY statement, group the courses for the above table.
CODE:
--task#3
SELECT
Courses,
COUNT(*) AS Number_of_Students
FROM studentss
GROUP BY Courses;
OUTPUT:
3
AIR UNIVERISTY, ISLAMABAD
Department of Electrical & Computer Engineering
Task 4:
Select maximum of the Reg no and smallest valued course code for the above given
table.
CODE:
--task#4
SELECT
MAX(Reg_No) AS Max_Reg_No,
MIN(Course_Code) AS Min_Course_Code
FROM studentss;
OUTPUT:
Task 5:
Find the length of each record for the first column in the above table as MAXIMUM
LENGTH.
CODE:
--task#5
SELECT
FName,
LEN(FName) AS Name_Length
FROM studentss
OUTPUT:
4
AIR UNIVERISTY, ISLAMABAD
Department of Electrical & Computer Engineering
CODE:
CREATE TABLE Orders (
O_Id INT,
OrderDate DATE,
OrderPrice INT,
Customer VARCHAR(100)
);
INSERT INTO Orders (O_Id, OrderDate, OrderPrice, Customer)
VALUES (1, '2008-11-12', 1000, 'Hansen');
INSERT INTO Orders (O_Id, OrderDate, OrderPrice, Customer)
VALUES (2, '2008-10-23', 1600, 'Nilsen');
INSERT INTO Orders (O_Id, OrderDate, OrderPrice, Customer)
VALUES (3, '2008-09-02', 700, 'Hansen');
INSERT INTO Orders (O_Id, OrderDate, OrderPrice, Customer)
VALUES (4, '2008-09-03', 300, 'Hansen');
INSERT INTO Orders (O_Id, OrderDate, OrderPrice, Customer)
VALUES (5, '2008-08-30', 2000, 'Jensen');
INSERT INTO Orders (O_Id, OrderDate, OrderPrice, Customer)
VALUES (6, '2008-10-04', 100, 'Nilsen');
5
AIR UNIVERISTY, ISLAMABAD
Department of Electrical & Computer Engineering
--task 6
SELECT AVG(OrderPrice) AS AverageOrderPrice
FROM Orders;
Output:
Task 7:
Find if the customers "Hansen" or "Nilsen" have a total order of less than 2100 for the
following
CODE:
--task 7
SELECT Customer, OrderPrice
FROM Orders
WHERE OrderPrice > 1800;
OUTPUT:
Task 8:
Find the total sum (total order) of each customer.
CODE:
--task 8
SELECT Customer, SUM(OrderPrice) AS TotalOrder
FROM Orders
GROUP BY Customer;
OUTPUT:
END