0% found this document useful (0 votes)
2 views

activity3_batch2

The document outlines SQL commands for creating a database and two tables: STUDENT and COURSE_ENROLLMENT, including their respective fields and primary/foreign key relationships. It also includes several SQL queries for inserting data into these tables and performing various calculations and transformations on the data, such as counting students and manipulating string lengths. The document demonstrates the use of SQL functions like COUNT, LENGTH, and CONCAT to derive new information from the existing data.

Uploaded by

ares.g1202
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

activity3_batch2

The document outlines SQL commands for creating a database and two tables: STUDENT and COURSE_ENROLLMENT, including their respective fields and primary/foreign key relationships. It also includes several SQL queries for inserting data into these tables and performing various calculations and transformations on the data, such as counting students and manipulating string lengths. The document demonstrates the use of SQL functions like COUNT, LENGTH, and CONCAT to derive new information from the existing data.

Uploaded by

ares.g1202
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

create database activity3_Batch2;

2-4.
create table STUDENT(STU_ID VARCHAR(6) PRIMARY KEY, STU_NAME VARCHAR(40) NOT NULL,
STU_MAJOR CHAR(35), CAMPUS_AREA VARCHAR(5) NOT NULL, STU_COUNTRY VARCHAR(20) NOT
NULL, STU_PHONE VARCHAR(15) NOT NULL);
Query OK, 0 rows affected (0.01 sec)

5-7.
create table COURSE_ENROLLMENT(
-> ENROLL_ID VARCHAR(6) PRIMARY KEY,
-> COURSE_NAME VARCHAR(35) NOT NULL,
-> INSTRUCTOR_NAME VARCHAR(20),
-> COURSE_COUNTRY VARCHAR(20) NOT NULL,
-> CONTACT_NUMBER VARCHAR(15) NOT NULL,
-> STU_ID VARCHAR(6),
-> FOREIGN KEY(STU_ID) REFERENCES
-> STUDENT(STU_ID));
Query OK, 0 rows affected (0.05 sec)

8-10.
mysql> INSERT INTO STUDENT VALUES
-> ("S001","Alice Johnson","Computer Science","A1","USA","123-456-7890"),
-> ("S002","Mark Davis","Business Admin","B2","Canada","987-654-3210"),
-> ("S003","Sophia Lee","Mechanical Eng","C3","UK","456-789-1234");
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> INSERT INTO COURSE_ENROLLMENT VALUES


-> ("E001","Database Systems","Dr. SMith","USA","111-222-3333","S001"),
-> ("E002","Marketing Strategy","Prof. Brown","Canada","444-555-6666","S002"),
-> ("E003","Thermodynamics","Dr. Williams","UK","777-888-9999","S003");
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0

11.
mysql> SELECT COUNT(*) * 2 AS DoubleStudentCount
-> FROM STUDENT;

12.
mysql> SELECT SQRT(LENGTH(STU_NAME)) AS RootNameLength FROM STUDENT LIMIT 1;

13.
mysql> select ABS(length(COURSE_NAME)-10) as AbsoluteCourseLength from
COURSE_ENROLLMENT;

14.
mysql> SELECT MOD(LENGTH(STU_PHONE), 7) AS PhoneLengthMod FROM STUDENT;

15.
mysql> SELECT POWER(LENGTH(CONTACT_NUMBER), 2) AS SquaredContactLength FROM
COURSE_ENROLLMENT;

16-20.
mysql> SELECT STU_ID,
-> STU_NAME,
-> FLOOR(length(STU_PHONE)/2) as HalfPhoneLength,
-> ABS(length(STU_COUNTRY)-10) as CountryLengthDiff,
-> ROUND(length(CAMPUS_AREA) * 1.10) as AdjustedCampusArea,
-> SQRT(length(STU_MAJOR)) as MajorSquared,
-> CEIL(LENGTH(STU_PHONE) * 1.05) AS IncreasedPhoneLength
-> FROM STUDENT
-> ORDER BY IncreasedPhoneLength DESC;

21-25.
SELECT CAMPUS_AREA,
STU_ID,
CONCAT(REVERSE(STU_ID), ' - Count: ', COUNT(*)) AS MixedOutput
FROM STUDENT
GROUP BY CAMPUS_AREA, STU_ID
ORDER BY STU_PHONE ASC;

26-30.
SELECT
STU_ID,
STU_NAME,
EXP(LENGTH(STU_NAME)) AS Scaled_Exponential, -- Apply exponential function to
name length
REVERSE(STU_NAME) AS ReversedName, -- Reverse the student name
CONCAT('Student: ', REVERSE(STU_NAME)) AS PrefixedReversedName, -- Prefix the
reversed name
CONCAT(STU_NAME, ' (Length: ', LENGTH(STU_NAME), ')') AS NameWithLength --
Append name length
FROM
Student
GROUP BY
STU_ID, STU_NAME
ORDER BY
STU_ID ASC; -- Order by STU_ID in ascending order

You might also like