0% found this document useful (0 votes)
2 views6 pages

Questions

The document outlines a series of SQL queries categorized into Basic, Intermediate, and Advanced levels, focusing on retrieving various statistics and information from student and score tables. It includes tasks such as calculating averages, counts, and ranks, as well as performing different types of joins. Additionally, it provides sample tables for students and scores, along with SQL commands for creating and inserting data into these tables.
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)
2 views6 pages

Questions

The document outlines a series of SQL queries categorized into Basic, Intermediate, and Advanced levels, focusing on retrieving various statistics and information from student and score tables. It includes tasks such as calculating averages, counts, and ranks, as well as performing different types of joins. Additionally, it provides sample tables for students and scores, along with SQL commands for creating and inserting data into these tables.
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
You are on page 1/ 6

Basic Level (20 Questions)

1. Get all entries with marks higher than the average marks.
2. Get the names of students with the highest marks.
3. Get the lowest marks for each year.
4. Get the total count of entries for each caste.
5. Get the count of unique years.
6. Get the entries where the marks are equal to the lowest marks in 2022.
7. Get the average marks for males (M).
8. Get the names of students with marks less than the highest marks in 2023.
9. Get all entries from the city with the highest average marks.
10. Get the total marks for each gender.
11. Get all entries with marks less than the average marks.
12. Get the names of students with the lowest marks.
13. Get the highest marks for each year.
14. Get the total count of entries for each region.
15. Get the entries where the marks are equal to the highest marks in 2021.
16. Get the average marks for females (F).
17. Get the names of students with marks greater than the lowest marks in
2023.
18. Get all entries from the city with the lowest average marks.
19. Get the total marks for each caste.
20. Get the average marks for each year.

Intermediate Level (20 Questions)

1. Get the names of students with marks greater than the highest marks of
2024.
2. Get the average marks for each city where the marks are higher than the
average marks.
3. Get the names and marks of the top 5 students for each year.
4. Get the highest marks for each caste.
5. Get the names of students with marks in the top 10% for their caste.
6. Get the city with the highest count of entries.
7. Get the average marks for each year where the marks are higher than the
average marks for that year.
8. Get the total marks for each city where the marks are greater than 80.
9. Get the names of students with marks greater than the highest marks of
their gender.
10. Get the lowest marks for each city where the marks are less than the
average marks for that city.
11. Get the names of students with marks higher than the average marks for
their region.
12. Get the names of students with the highest marks in each caste and region.
13. Get the average marks for each gender and region where the marks are
higher than the average marks.
14. Get the count of entries for each year where the marks are higher than the
average marks for that year.
15. Get the names of students with marks higher than the highest marks for
their city.
16. Get the total marks for each year where the marks are higher than the
average marks for that year.
17. Get the names of students with marks greater than the highest marks of
their caste.
18. Get the average marks for each city where the marks are higher than the
highest marks for that city.
19. Get the count of entries for each caste and region where the marks are
higher than the average marks for their caste.
20. Get the names of students with marks higher than the average marks for
their year and city.

Advanced Level (20 Questions)

3. Get the names of students with marks higher than the average marks for
their year and region.
4. Get the total marks for each caste and gender where the marks are higher
than the average marks for their caste.
5. Get the average marks for each year and city where the marks are higher
than the average marks for their year.
6. Get the count of entries for each gender and region where the marks are
higher than the highest marks for their gender.
7. Get the names of students with marks higher than the highest marks for
their caste and region.
8. Get the total marks for each year and city where the marks are higher than
the average marks for their year.
9. Get the average marks for each caste and gender where the marks are
higher than the highest marks for their caste.
10. Get the count of entries for each year and region where the marks are
higher than the average marks for their year.
11. Get the names of students with marks higher than the highest marks for
their year and caste.
12. Get the total marks for each gender and region where the marks are higher
than the average marks for their gender.
13. Get the average marks for each caste and city where the marks are higher
than the average marks for their caste.
14. Get the count of entries for each year and city where the marks are higher
than the highest marks for their year.
15. Get the names of students with marks higher than the highest marks for
their year and region.
16. Get the total marks for each caste and region where the marks are higher
than the average marks for their caste.
17. Get the average marks for each gender and city where the marks are higher
than the highest marks for their gender.
18. Get the count of entries for each year and gender where the marks are
higher than the average marks for their year.
19. Get the names of students with marks higher than the highest marks for
their caste and city.
20. Get the total marks for each year and region where the marks are higher
than the highest marks for their year.
Sample Tables

Students Table
student_id student_name age major

1 Alice 20 Computer Science

2 Bob 21 Mathematics

3 Charlie 22 Physics

4 David 20 Biology

5 Eve 21 Chemistry

Scores Table
score_id student_id subject score

1 1 Math 85

2 1 Science 90

3 2 Math 78

4 2 Science 82

5 3 Math 88

6 3 Science 91

7 4 Math 72

8 4 Science 75

9 5 Math 89

10 5 Science 94

CREATE TABLE students (


student_id INT PRIMARY KEY,
student_name VARCHAR(50),
age INT,
major VARCHAR(50)
);

INSERT INTO students (student_id, student_name, age, major) VALUES


(1, 'Alice', 20, 'Computer Science'),
(2, 'Bob', 21, 'Mathematics'),
(3, 'Charlie', 22, 'Physics'),
(4, 'David', 20, 'Biology'),
(5, 'Eve', 21, 'Chemistry');
CREATE TABLE scores (
score_id INT PRIMARY KEY,
student_id INT,
subject VARCHAR(50),
score INT,
FOREIGN KEY (student_id) REFERENCES students(student_id)
);

INSERT INTO scores (score_id, student_id, subject, score) VALUES


(1, 1, 'Math', 85),
(2, 1, 'Science', 90),
(3, 2, 'Math', 78),
(4, 2, 'Science', 82),
(5, 3, 'Math', 88),
(6, 3, 'Science', 91),
(7, 4, 'Math', 72),
(8, 4, 'Science', 75),
(9, 5, 'Math', 89),
(10, 5, 'Science', 94);

Inner Join Queries

1. Retrieve student names and their corresponding scores.

2. Get the list of students along with their subjects and scores.

3. Retrieve student names and scores for the 'Math' subject.

4. Get the names and scores of students who have scored more than 80 in
any subject.

5. Retrieve the student names, subjects, and scores, ordered by student


names.

Outer Join (Left Join) Queries

1. Retrieve all students and their scores, including students with no scores.

2. Get the list of students and their subjects and scores, including students
without scores.

3. Retrieve student names and scores for the 'Math' subject, including
students without scores.

4. Get the names and scores of all students who have scored more than 80 in
any subject, including students without scores.
5. Retrieve the student names, subjects, and scores, ordered by student
names, including students without scores.

Outer Join (Right Join) Queries

1. Retrieve all scores and their corresponding students, including scores with
no students.

2. Get the list of subjects and their scores along with student names, including
scores without students.

3. Retrieve subjects and scores for the 'Math' subject along with student
names, including scores without students.

4. Get the list of subjects and scores where scores are more than 80, including
scores without students.

5. Retrieve the subjects and scores ordered by student names, including


scores without students.

Self Join Queries

1. Retrieve pairs of students who are of the same age.

2. Get the list of students who share the same major.

3. Retrieve students who are younger than another student with the same
major.

4. Get the pairs of students with different majors.

5. Retrieve students who have the same age but different majors.

Cross Join Queries

1. Get the Cartesian product of students and scores.

2. Retrieve all combinations of students and subjects.

3. Get the list of all possible pairs of student names.

4. Retrieve all possible pairs of student names and scores.

5. Get the Cartesian product of student names and subjects.

Window Functions: Over, Partition, Rank Queries

1. Calculate the rank of students based on their scores.


2. Retrieve the cumulative score of students.

3. Get the average score of students over different partitions.

4. Retrieve the rank of students within their major.

5. Get the difference between the current score and the previous score.

You might also like