我是MySQL的新手,我没有得到如何为我的问题编写查询。我有一张名为" Station"并且有一列名为" City"。我试图从Station找到城市名称的最大和最小长度。
条件是 -
答案 0 :(得分:1)
SELECT a.*
FROM (
select City, length( City )
from Station
where length( City ) = ( select max( length( City ) ) from Station )
order by city
limit 1
) a
UNION ALL
SELECT b.*
FROM (
select City, length( City )
from Station
where length( City ) = ( select min( length( City ) ) from Station )
order by city
limit 1
) b;
你可以编辑max到min来获得城市的最小长度
我认为如果你想在一个查询中使用它会更复杂