School_Ranking_Analysis_Solution
School_Ranking_Analysis_Solution
School_Ranking_Analysis_Solution
1. Write a query to create a students table with the student ID, first name, last
name, class, and age fields and ensure that the last name, first name, and
student ID fields have the NOT NULL constraint and that the student ID field is
a primary key
SQL code:
CREATE TABLE lep_5.students (
s_id INT NOT NULL,
s_fname varchar(45) NOT NULL,
s_lname varchar(45) NOT NULL,
class varchar(45) NULL,
age INT NOT NULL,
PRIMARY KEY(s_id));
2. Write a query to create a marksheet table with score, year, ranking, class,
and student ID fields
SQL code:
CREATE TABLE lep_5.marksheet (
score INT NOT NULL,
year INT NULL,
class varchar(45) NULL,
ranking varchar(45) NULL,
s_id INT NOT NULL);
3. Write a query to insert values into the students and marksheet tables
SQL code:
SELECT s_id,s_fname FROM lep_5.students WHERE s_lname = 'kumar' AND
age>=16;
Output:
5. Write a query to display the details of every student from the marksheet table
whose score is between 800 and 1000
SQL code:
SELECT * FROM lep_5.marksheet WHERE score BETWEEN 800 AND 1000 ;
Output:
6. Write a query to increase the score in the marksheet table by five and create a
new score column to display this new score
SQL code:
SELECT * ,score+5 as new_score FROM lep_5.marksheet ;
Output:
7. Write a query to display the marksheet table in descending order of the score
SQL code:
SELECT * FROM lep_5.marksheet ORDER BY score DESC ;
Output:
SQL code:
SELECT * FROM lep_5.students WHERE s_fname LIKE 's%';
Output: