Q.1 MYSQL

SQL Queries to create table student and table Subjects.

Q.1 Create a database School.

Solution :-  

create database school;

Q.2 Access Database

Solution  :- 

use school

Q.3(a) Create table Student.

Solution  :- 

create table student
(
studentId int primary key,
StudentName varchar(100),
Age int,
class varchar(100),
marks int );

Q.3(b) Create table Subject.

Solution  :- 

create table subject
(
subjectid int primary key,
subjectName varchar(100),
teachername varchar(100),
studentId int,foreign key (studentId) references student(studentId));

Q.4(a) Insert into table Student. 

Solution :- 

insert into student values(1,”Alice Johnson”,17,”12th”,85);
insert into student values(2,”Bob Smith”,18,”12th”,92);
insert into student values(3,”Charlie Brown”,17,”11th”,74);
insert into student values(4,”Diana Prince”,18,”12th”,88);
insert into student values(5,”Edward Wilson”,17,”11th”,64);
insert into student values(6,”John Doe”,18,”12th”,85);

Q.4 (b) Insert into table Subjects . 

Solution :- 

insert into subject values(1,”Mathematics”,”Mr. Carter”,1);
insert into subject values(2,”Physics”,”Dr. Evans”,2);
insert into subject values(3,”Chemistry”,”Mrs. Taylor”,3);
insert into subject values(4,”Biology”,”Dr. Smith”,6);
insert into subject values(5,”English”,”Ms. Johnson”,4);
insert into subject values(6,”History”,”Mr. Brown”,5);

Q.5 Retrieve the names of students who scored more than 80 marks.

Solution :- 

SELECT StudentName FROM Student WHERE Marks > 80;

Q.6 Write a query to display the student names along with their respective subject names using a join.

Solution :- 

SELECT S.StudentName, Sub.SubjectName
FROM Student S
INNER JOIN Subject Sub ON S.StudentID = Sub.StudentID;

Q.7 Count the total number of students in class “12th”.

Solution :- 

 SELECT COUNT(*) AS TotalStudents FROM Student WHERE Class = ’12th’;

Q.8 Calculate the average marks of all students in the Students

Solution :- 

SELECT AVG(Marks) AS AverageMarks FROM Student;

Leave a Reply

Your email address will not be published. Required fields are marked *

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.