HackerRank - Get shortest and longest city name using Sql Server.

preview_player
Показать описание
Solution for HackerRank question, list shortest and longest city name string length.

This query first selects the smallest city by sorting by city length in ascending order, and then by city name in ascending order. It uses TOP 1 to get only the top result.

Then, it performs a second query to get the largest city by sorting by city length in descending order, and then by city name in descending order. Again, it uses TOP 1 to get only the top result.

The UNION ALL operator combines the results of the two queries into a single result set. This will give you the smallest and largest cities based on their lengths from the entire dataset.

how to use CTE statement
how to use UNION ALL statement

@softwareNuggets, #softwareNuggets,
Рекомендации по теме