我正在试图解决HackerRank中的一个问题,称为“您的天气观测站5",这个问题要求返回提供的表中最短和最长的城市名称。
为澄清我的困惑而进行的示范:
SELECT MIN(City) FROM STATION;输出:有4个字符的城市名称。
SELECT MIN(LEN(City)) FROM STATION;输出: 3。
为什么MIN()函数的输出不是有3个字符的城市名称?我很感激你对这种行为的解释。
发布于 2022-02-17 17:45:06
当您"MIN“一个字符串列时,您将得到字母顺序的第一个列表。它与字符串的长度无关。
例如,“阿尔伯克基”按字母顺序出现在“迈阿密”之前。
发布于 2022-06-01 20:16:45
如果有人还在寻找解决方案,我从黑客级别进行了这个挑战,这是一个有效的查询:
select
city,
length(city)
from station
where city =
(
select
city
from station
where length(city) =
(
select
max(length(city))
from station
limit 1
)
order by 1 asc
limit 1
) or city =
(
select
city
from station
where length(city) =
(
select
min(length(city))
from station
limit 1
)
order by 1
limit 1
)
order by 1https://stackoverflow.com/questions/71162906
复制相似问题