Return schools and classes with more than 2 students enrolled in Maths and Physics | SQL Joins scenario question

 DROP TABLE IF EXISTS Students;


DROP TABLE IF EXISTS Enrollments;


CREATE TABLE Students (

    StudentID INT NOT NULL PRIMARY KEY,

    School VARCHAR(100) NOT NULL,

    Class VARCHAR(50) NOT NULL

);


CREATE TABLE Enrollments (

    StudentID INT NOT NULL,

    Subject VARCHAR(100) NOT NULL 

);



INSERT INTO Students (StudentID, School, Class) VALUES

(1, 'Greenfield High', '10A'),

(2, 'Greenfield High', '10A'),

(3, 'Blue River School', '10A'),

(4, 'Blue River School', '10A'),

(5, 'Sunshine Academy', '8C'),

(6, 'Sunshine Academy', '8C'),

(7, 'Greenfield High', '10A'),

(8, 'Blue River School', '9B'),

(9, 'Sunshine Academy', '8C'),

(10, 'Greenfield High', '11A');


INSERT INTO Enrollments (StudentID, Subject) VALUES

(1, 'Maths'),

(1, 'Physics'),

(2, 'Maths'),

(2, 'Physics'),

(3, 'Maths'),

(3, 'Chemistry'),

(4, 'Physics'),

(4, 'Maths'),

(5, 'Maths'),

(6, 'Physics'),

(6, 'Maths'),

(7, 'Physics'),

(8, 'Maths'),

(8, 'Physics'),

(9, 'Chemistry'),

(10, 'Maths');

Comments

Popular posts from this blog

50 Essential SQL Questions to Land Your Dream Job

How to find all the customers who placed orders on three consecutive days | SQL Scenario questions

ACCENTURE SQL INTERVIEW QUESTION | Change the ProductIDs