Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

SQL Advance Test

The document describes 4 questions about SQL queries. Question 1 asks to write a query to generate a report with student names, grades and marks in descending order based on certain criteria. Question 2 asks to output all symmetric pairs from a table in ascending order. Question 3 asks to query the shortest and longest city names from a table along with their lengths. Question 4 asks to print a list of employee names from a table in alphabetical order.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

SQL Advance Test

The document describes 4 questions about SQL queries. Question 1 asks to write a query to generate a report with student names, grades and marks in descending order based on certain criteria. Question 2 asks to output all symmetric pairs from a table in ascending order. Question 3 asks to query the shortest and longest city names from a table along with their lengths. Question 4 asks to print a list of employee names from a table in alphabetical order.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Question 1:

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.

Sample Input
Sample Output

Maria 10 99
Jane 9 81
Julia 9 88
Scarlet 8 78
NULL 7 63
NULL 7 68

Note

Print "NULL" as the name if the grade is less than 8.

Explanation

Consider the following table with the grades assigned to the students:
So, the following students got 8, 9 or 10 grades:

● Maria (grade 10)

● Jane (grade 9)

● Julia (grade 9)

● Scarlet (grade 8)

1. Write a SQL query for it?

2. Question :

You are given a table, Functions, containing two columns: X and Y.


Two pairs (X1, Y1) and (X2, Y2) are said to be symmetric pairs if X1 = Y2 and X2 = Y1.

Write a query to output all such symmetric pairs in ascending order by the value of X. List the rows

such that X1 ≤ Y1.

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.

The STATION table is described as follows:

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.

Choose ABC, because it comes first alphabetically.

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

table in alphabetical order.

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

You might also like