0% found this document useful (0 votes)
49 views1 page

Input Format: Abc 3 Pqrs 4

This document contains two SQL queries. The first query selects the distinct city names from the STATION table where the ID number is even, excluding duplicates. The second query selects the city names with the shortest and longest lengths from STATION, including the length of each name, prioritizing length then alphabetical order if there are ties.

Uploaded by

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

Input Format: Abc 3 Pqrs 4

This document contains two SQL queries. The first query selects the distinct city names from the STATION table where the ID number is even, excluding duplicates. The second query selects the city names with the shortest and longest lengths from STATION, including the length of each name, prioritizing length then alphabetical order if there are ties.

Uploaded by

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

Query a list of CITY names from STATION with even ID numbers only.

You may print the results in any order, but


must exclude duplicates from your answer.
Input Format
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western
longitude.

Answer
SELECT DISTINCT CITY FROM STATION
WHERE MOD(ID, 2) = 0;

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.
Input Format
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western
longitude.
Sample Input
Let's say that CITY only has four entries: DEF, ABC, PQRS and WXY
Sample Output
ABC 3
PQRS 4
Note: You can write two separate queries to get the desired output. It need not be a single query.

Answer
SELECT City, LENGTH(City)
FROM (SELECT City
FROM Station
ORDER BY LENGTH(City), City)
WHERE ROWNUM = 1;
SELECT City, LENGTH(City)
FROM (SELECT City
FROM Station
ORDER BY LENGTH(City) DESC, City)
WHERE ROWNUM = 1;

You might also like