Knowee
Questions
Features
Study Tools

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 InputFor example, CITY has four entries: DEF, ABC, PQRS and WXY.Sample OutputABC 3PQRS 4ExplanationWhen 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.NoteYou can write two separate queries to get the desired output. It need not be a single query

Question

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 InputFor example, CITY has four entries: DEF, ABC, PQRS and WXY.Sample OutputABC 3PQRS 4ExplanationWhen 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.NoteYou can write two separate queries to get the desired output. It need not be a single query

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

Solution

This problem is a SQL problem. You are asked to find the city with the shortest and longest name from the STATION table. If there are multiple cities with the same shortest or longest name, you should select the one that comes first alphabetically.

Here is the SQL solution:

SELECT CITY, LENGTH(CITY) as LEN
FROM STATION
ORDER BY LEN ASC, CITY ASC
LIMIT 1;

SELECT CITY, LENGTH(CITY) as LEN
FROM STATION
ORDER BY LEN DESC, CITY ASC
LIMIT 1;

The first query will give you the city with the shortest name. If there are multiple cities with the same shortest length, it will return the one that comes first alphabetically. The second query will give you the city with the longest name, and if there are multiple cities with the same longest length, it will return the one that comes first alphabetically.

This problem has been solved

Similar Questions

Create a view 'ShortestCity' to find the shortest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest city, choose the one that comes first when ordered alphabetically.TABLE: STATIONNOTE: All Records are PrepopulatedInput format :The input tables are already prepopulated, as given in the problem statement.Output format :The output should display the name of the city with the shortest name and the length of the city name as shown below.

Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.The STATION table is described as follows:where LAT_N is the northern latitude and LONG_W is the western longitude.

Query a list of CITY and STATE from the STATION table.The STATION table is described as follows:where LAT_N is the northern latitude and LONG_W is the western longitude.

Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.The STATION table is described as follows:where LAT_N is the northern latitude and LONG_W is the western longitude.For example, if there are three records in the table with CITY values 'New York', 'New York', 'Bengalaru', there are 2 different city names: 'New York' and 'Bengalaru'. The query returns , because .

Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates.Input FormatThe STATION table is described as follows:where LAT_N is the northern latitude and LONG_W is the western longitude.

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.