0% found this document useful (0 votes)
21 views2 pages

SQL Unsolved

The document outlines a problem statement to find the highest score achieved per subject in the first attempt and the student who scored it. It provides the schema for subjects, students, and results tables and sample data to return results like "maths 80 Shubham". An initial SQL query is shown but returns incorrect student names.

Uploaded by

Shubham Waykole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

SQL Unsolved

The document outlines a problem statement to find the highest score achieved per subject in the first attempt and the student who scored it. It provides the schema for subjects, students, and results tables and sample data to return results like "maths 80 Shubham". An initial SQL query is shown but returns incorrect student names.

Uploaded by

Shubham Waykole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

===================================================================================

==========
SCHEMA
===================================================================================
==========
Subject — Id, Name
Student — Id, Name
Result — Id, Sub_id, Stu_id, Marks, Attempt_no

===================================================================================
==========
PROBLEM STATEMENT
===================================================================================
==========
Find out the highest score achieved per subject in the first attempt and who scored
it ?
Sample results should be like
maths 80 Shubham
science 90 kanchan
English 70 yash
===================================================================================
==========
DATA CREATED FOR ABLVE SAMPLE OUTPUT
===================================================================================
==========
DATA ->
student table
id name
1 shubham
2 kanchan
3 yash

subject table
id name
1 maths
2 science
3 english

result table
id sub_id stu_id marks attemp_no
1 1 1 80 1
2 2 1 10 1
3 3 1 10 1
4 1 2 20 1
5 2 2 90 1
6 3 2 20 1
7 1 3 30 1
8 2 3 30 1
9 3 3 70 1

===================================================================================
===========
TRIED THIS BUT stu.name is incorrect
===================================================================================
===========
select sub.name,max(r.marks), stu.name
FROM
student_result.subject sub
INNER JOIN student_result.result r ON sub.id = r.sub_id
INNER JOIN student_result.student stu ON stu.id = r.stu_id
GROUP BY sub.name;

OUTPUT
name max(r.marks) name
english 70 shubham
science 90 shubham
maths 80 shubham

You might also like