0% found this document useful (0 votes)
13 views3 pages

SQL Assignment

The document outlines an SQL assignment involving the creation of a 'Student' table with specific fields and sample data. It includes SQL queries to manipulate and retrieve data such as fetching first names in uppercase, unique majors, first three characters of first names, and the position of a specific letter in a name. The document provides both the SQL commands and expected output for each query.

Uploaded by

abhaypersonal9
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)
13 views3 pages

SQL Assignment

The document outlines an SQL assignment involving the creation of a 'Student' table with specific fields and sample data. It includes SQL queries to manipulate and retrieve data such as fetching first names in uppercase, unique majors, first three characters of first names, and the position of a specific letter in a name. The document provides both the SQL commands and expected output for each query.

Uploaded by

abhaypersonal9
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

SQL Assignment

1Q. Create the following table named "Student" and write SQL queries for
the tasks that follow:
Table Structure and Sample Data:

CREATE TABLE Student (


STUDENT_ID INT,
FIRST_NAME VARCHAR(50),
LAST_NAME VARCHAR(50),
GPA DECIMAL(4,2),
ENROLLMENT_DATE DATETIME,
MAJOR VARCHAR(100)
);

-- Sample Data Insertion


INSERT INTO Student (STUDENT_ID, FIRST_NAME, LAST_NAME, GPA,
ENROLLMENT_DATE, MAJOR) VALUES
(201, 'Shivansh', 'Mahajan', 8.79, '2021-09-01 09:30', 'Computer
Science'),
(202, 'Umesh', 'Sharma', 8.44, '2021-09-01 08:30', 'Mathematics'),
(203, 'Rakesh', 'Kumar', 5.6, '2021-09-01 10:00', 'Biology'),
(204, 'Radha', 'Sharma', 9.2, '2021-09-01 12:45', 'Chemistry'),
(205, 'Kush', 'Kumar', 7.85, '2021-09-01 08:30', 'Physics'),
(206, 'Prem', 'Chopra', 9.56, '2021-09-01 09:24', 'History'),
(207, 'Pankaj', 'Vats', 9.78, '2021-09-01 02:00', 'English'),
(208, 'Navleen', 'Kaur', 7.0, '2021-09-01 06:30', 'Mathematics');

1. Write a SQL query to fetch "FIRST_NAME" from the Student table in upper
case and use ALIAS name as STUDENT_NAME.

SELECT UPPER(FIRST_NAME) AS STUDENT_NAME


FROM Student;

Output:

 SHIVANSH
 UMESH
 RAKESH
 RADHA
 KUSH
 PREM
 PANKAJ
 NAVLEEN

2. Write a SQL query to fetch unique values of MAJOR Subjects from Student
table.

SELECT DISTINCT MAJOR


FROM Student;

Output:

 Computer Science
 Mathematics
 Biology
 Chemistry
 Physics
 History
 English

3. Write a SQL query to print the first 3 characters of FIRST_NAME from Student
table.

SELECT SUBSTRING(FIRST_NAME, 1, 3) AS FIRST3


FROM Student;

Output:

 Shi
 Ume
 Rak
 Rad
 Kus
 Pre
 Pan
 Nav
4. Write a SQL query to find the position of alphabet ('a') in the first name
column 'Shivansh' from Student table.

SELECT POSITION('a' IN FIRST_NAME) AS POSITION_OF_A


FROM Student
WHERE FIRST_NAME = 'Shivansh';

Output:

 5

You might also like