Filter Students by their highest marks

Punuth

I have a mysql table

table name 'results'

Reg.No  SubjectCode  Attempt  Grade  Marks
112108  CMIS 1113    1        D      17
112110  CMIS 1114    1        A      85
112119  CMIS 1114    1        D      18
112108  CMIS 1113    2        D+     25
112110  CMIS 1113    1        D+     25
112107  CMIS 1113    1        B      70
112108  CMIS 1113    3        C      40
112110  CMIS 1113    2        C      40
112119  CMIS 1114    2        C      42
112120  CMIS 1114    1        D      17

This is about students' results.
Students need at least a "C" (marks>40) to pass the subject.
Until pass, students can have several attempts.
But from the second attempt maximum grade they can get is "C"
So students who was unable to pass the subject in first attempt,used to have another try until they pass the subjects
So for final results sheet the highest result will be take into account in each subjects.(highest results is given by the highest marks)
So for example highest marks of 112108 for CMIS 1113 is 40.
So likewise I want to get the students results for ecch subjects(But always maximum marks will be take into account)
Actually my expected results table should be like this

Reg.No  SubjectCode  Attempt  Grade  Marks
112110  CMIS 1114    1        A      85
112107  CMIS 1113    1        B      70
112108  CMIS 1113    3        C      40
112110  CMIS 1113    2        C      40
112119  CMIS 1114    2        C      42
112120  CMIS 1114    1        D      17

So how can I retrieve these data using sql query?

2ndkauboy

To get only one value per student, you group by Reg.No and SubjectCode and then get the max value for each subject. This query should work:

SELECT      
    `Reg.No`,
    `SubjectCode`,
    `Attempt`,
    `Grade`,
    MAX(`marks`) AS marks
FROM        
    `results` 
GROUP BY    
    `Reg.No`, `SubjectCode`  

In order to get all columns, you need two queries, which can be put together with a subquery. It will look like this:

SELECT * 
FROM
    (SELECT * 
     FROM `results` 
     ORDER BY `Grade` ASC) AS t
GROUP BY    
    `Reg.No`, `SubjectCode` 
ORDER BY    
    `Grade` ASC

The "inner query" will get all results and order the rows by the Grade column from low to high. The "outer query" will than just group them (without the usage of the MAX function). This will result in only the last row for each grouping, which is than the max result (as we ordered it that way in the "inner query").

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Filter rows from a data frame based on the highest index and values from column

From Dev

Add specific points on highest marks

From Dev

jquery filter array of objects to find object property with highest value

From Dev

Does VSTO have access to the contents of the Excel Filter check marks?

From Dev

Filter students that have not passed a subject yet

From Dev

filter text file rows by certain column without quotation marks

From Dev

How to find ranks for only students who got pass marks?

From Dev

Best Data Structure to store marks and ranks of students

From Dev

Object filter by N highest numeric values (of keys)

From Dev

Query or Filter the Highest Value with Conditions

From Dev

Filter list of dicts by highest value of dict and taking reversed values into account

From Dev

Get list of Students who scored "x" marks Java8 List<Student> to Map<Marks,List<Name>> with limit to number of Names

From Dev

Print the students with the top marks

From Dev

Add specific points on highest marks

From Dev

Find highest points of two students in a section

From Dev

First three Groups with Highest Marks should have specific points

From Dev

Does VSTO have access to the contents of the Excel Filter check marks?

From Dev

Filter Rows by highest version

From Dev

Filter students that have not passed a subject yet

From Dev

Mysql Query to fetch second lowest marks for all students in a table

From Dev

How do you filter for rows in a table where the count is highest in Django?

From Dev

How to find ranks for only students who got pass marks?

From Dev

How to count students who got equal marks and also show the marks of that group in SQL Server

From Dev

How to get name of students of three highest mark takers in each subject

From Dev

Getting Stream wise Highest Marks in SQL

From Dev

SQL Server - Filter by Highest Value

From Dev

How can I sort or filter a dictionary using the highest Int values?

From Dev

Find highest average in JavaScript 2d array of students scores

From Dev

product filter sortby highest or lowest using javascript/vue

Related Related

  1. 1

    Filter rows from a data frame based on the highest index and values from column

  2. 2

    Add specific points on highest marks

  3. 3

    jquery filter array of objects to find object property with highest value

  4. 4

    Does VSTO have access to the contents of the Excel Filter check marks?

  5. 5

    Filter students that have not passed a subject yet

  6. 6

    filter text file rows by certain column without quotation marks

  7. 7

    How to find ranks for only students who got pass marks?

  8. 8

    Best Data Structure to store marks and ranks of students

  9. 9

    Object filter by N highest numeric values (of keys)

  10. 10

    Query or Filter the Highest Value with Conditions

  11. 11

    Filter list of dicts by highest value of dict and taking reversed values into account

  12. 12

    Get list of Students who scored "x" marks Java8 List<Student> to Map<Marks,List<Name>> with limit to number of Names

  13. 13

    Print the students with the top marks

  14. 14

    Add specific points on highest marks

  15. 15

    Find highest points of two students in a section

  16. 16

    First three Groups with Highest Marks should have specific points

  17. 17

    Does VSTO have access to the contents of the Excel Filter check marks?

  18. 18

    Filter Rows by highest version

  19. 19

    Filter students that have not passed a subject yet

  20. 20

    Mysql Query to fetch second lowest marks for all students in a table

  21. 21

    How do you filter for rows in a table where the count is highest in Django?

  22. 22

    How to find ranks for only students who got pass marks?

  23. 23

    How to count students who got equal marks and also show the marks of that group in SQL Server

  24. 24

    How to get name of students of three highest mark takers in each subject

  25. 25

    Getting Stream wise Highest Marks in SQL

  26. 26

    SQL Server - Filter by Highest Value

  27. 27

    How can I sort or filter a dictionary using the highest Int values?

  28. 28

    Find highest average in JavaScript 2d array of students scores

  29. 29

    product filter sortby highest or lowest using javascript/vue

HotTag

Archive