Knowee
Questions
Features
Study Tools

You are given two tables: Students and Grades. Students contains three columns ID, Name and Marks.Grades contains the following data:Ketty gives Eve a task to generate a report containing three columns: Name, Grade and Mark. Ketty doesn't want the NAMES of those students who received a grade lower than 8. The report must be in descending order by grade -- i.e. higher grades are entered first. If there is more than one student with the same grade (8-10) assigned to them, order those particular students by their name alphabetically. Finally, if the grade is lower than 8, use "NULL" as their name and list them by their grades in descending order. If there is more than one student with the same grade (1-7) assigned to them, order those particular students by their marks in ascending order.Write a query to help Eve.

Question

You are given two tables: Students and Grades. Students contains three columns ID, Name and Marks.Grades contains the following data:Ketty gives Eve a task to generate a report containing three columns: Name, Grade and Mark. Ketty doesn't want the NAMES of those students who received a grade lower than 8. The report must be in descending order by grade -- i.e. higher grades are entered first. If there is more than one student with the same grade (8-10) assigned to them, order those particular students by their name alphabetically. Finally, if the grade is lower than 8, use "NULL" as their name and list them by their grades in descending order. If there is more than one student with the same grade (1-7) assigned to them, order those particular students by their marks in ascending order.Write a query to help Eve.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is the SQL query that Eve can use to generate the report:

SELECT 
    CASE 
        WHEN Grades.Grade >= 8 THEN Students.Name 
        ELSE 'NULL' 
    END AS Name, 
    Grades.Grade, 
    Students.Marks 
FROM 
    Students 
    INNER JOIN Grades ON Students.ID = Grades.ID 
WHERE 
    Grades.Grade >= 8 
ORDER BY 
    Grades.Grade DESC, 
    Students.Name, 
    Students.Marks;

This query first joins the Students and Grades tables on the ID column. It then selects the Name, Grade, and Marks columns, but replaces the Name with 'NULL' if the Grade is less than 8. The results are then ordered by Grade in descending order, then by Name in alphabetical order, and finally by Marks in ascending order.

This problem has been solved

Similar Questions

Given 3 tables, students(id, name) , courses(id, name) , grades(id, course_id, student_id, grade), for each student, get all the courses that he/she is enrolled in along with the grade he/she scored for each course. Order the result by the student name in ascending order and if there is a tie, break it with the course name in ascending order and if there is a tie break it with the grade in ascending order. Your query should output a table with the following columns (name, course, grade).

ou have a database that tracks students in the students table by student_id. Students may get warnings for low grades or poor behavior. The warnings are tracked in the warnings table where the student is referred to by student_id.You need to create a query that finds the first and last name of the student who has the most records in the warnings table. You begin typing your query:What should you type in the blank space? (Please type your answer all in lower case. Example: select)

Given 3 tables, students(id, name) , courses(id, name) , grades(id, course_id, student_id, grade), find the top 100 students based on their average grades sorted descendingly by the average grade and in case multiple students have the same average grade, sort them lexicographically in ascending order by their names. Your query should output a table with the following columns (name, average_grade).

For the following tables: Student(studentId, studentName, address)            ('S01', 'Nguyen Van An', 'Hanoi'),            ('S02', 'Pham Tuan Anh', 'Hanoi'),            ('S03', 'Nguyen Minh Quan', 'Danang')Result(studentId, subjectId, score)            ('S01', 'J01', 8),            ('S01', 'S01', 7),            ('S02', 'J01', 3)Subject(subjectId, subjectName)            ('S01', 'SQL Basics'),            ('J01', 'Programming Java'),            ('N01', 'Programming C#')and a query:  SELECT s.studentName, r.subjectId, r.scoreFROM asql.Student s JOIN asql.Result r ON s.studentId =r.studentIdWhat is the result of the query?Nguyen Van An J01 8Nguyen Van An S01 7Pham Tuan Anh J01 3Nguyen Van An J01 8Nguyen Van An S01 7Pham Tuan Anh J01 3Nguyen Minh Quan NULL NULLNguyen Van An Programming Java 8Nguyen Van An SQL Basics 7Pham Tuan Anh Programming Java 3Nguyen Van An J01 8Pham Tuan Anh J01 3Nguyen Minh Quan NULL NULL

Create a database of students using structures, where in each entry of the database will have the following fields:a name, which is a string with at most 128 characterstheir marks in physics, which is an int between 0 and 100their marks in chemistry, which is an int number between 0 and 100their marks in mathematics, which is an int number between 0 and 100You have to output a list of students in the following order.if a student 'A' has lower marks in physics than a student 'B', then A's data is listed before B.If A and B have the same physics marks and A has lower chemistry marks than B, then A is listed before B.If A and B have the same marks in physics and chemistry, and A has lower marks in mathematics than B, then A is listed before B.If all marks are equal and A's name precedes B's name in the dictionary order, then A is listed before B..Input Format :First line contains the number of students n, where 1<=n<=100.In following n lines each line contains(space separated)  a name and their respective marks in physics, chemistry, maths, where 0<=marks<=100.Output Format :Sorted database of n lines.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.