SQL Advance Test
SQL Advance Test
You are given two tables: Students and Grades. Students contains three columns ID, Name and
Marks.
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
Sample Input
Sample Output
Maria 10 99
Jane 9 81
Julia 9 88
Scarlet 8 78
NULL 7 63
NULL 7 68
Note
Explanation
Consider the following table with the grades assigned to the students:
So, the following students got 8, 9 or 10 grades:
● Jane (grade 9)
● Julia (grade 9)
● Scarlet (grade 8)
2. Question :
Write a query to output all such symmetric pairs in ascending order by the value of X. List the rows
Sample Input
Sample Output
20 20
20 21
22 23
Question 3:
Query the two cities in STATION with the shortest and longest CITY names, as well as their
respective lengths (i.e.: number of characters in the name). If there is more than one smallest
or largest city, choose the one that comes first when ordered alphabetically.
where LAT_N is the northern latitude and LONG_W is the western longitude.
Sample Input
For example, CITY has four entries: DEF, ABC, PQRS and WXY.
Sample Output
ABC 3
PQRS 4
Explanation
When ordered alphabetically, the CITY names are listed as ABC, DEF, PQRS, and WXY, with
lengths and . The longest name is PQRS, but there are options for shortest named city.
Note
You can write two separate queries to get the desired output. It need not be a single query.
Question 4:
Write a query that prints a list of employee names (i.e.: the name attribute) from the Employee
Input Format
The Employee table containing employee data for a company is described as follows:
where employee_id is an employee's ID number, name is their name, months is the total
number of months they've been working for the company, and salary is their monthly salary.
Sample Input
Sample Output
Angela
Bonnie
Frank
Joe
Kimberly
Lisa
Michael
Patrick
Rose
Todd