SQL select the longest char

2019-09-19 05:20发布

i have the table customer with column Name varchar(20), adresse varchar(50), tel varchar(10), etc.

how can i select the longest adresse ?

SELECT FROM customer 
WHERE adresse ?

4条回答
Emotional °昔
2楼-- · 2019-09-19 05:58
SELECT address FROM customer WHERE length(address) = (SELECT max(length(address)) FROM customer)
查看更多
Deceive 欺骗
3楼-- · 2019-09-19 06:01
select top (1) * from customer order by len(adresse) desc;
查看更多
别忘想泡老子
4楼-- · 2019-09-19 06:15

try this:

select max(len(adresse)) from customer 
查看更多
女痞
5楼-- · 2019-09-19 06:17

You can do it with a subquery:

select * from customer where len (adresse) = (
    select max (len (adresse)) from customer)

The inner query figures out the maximum length over all the adresse columns, and the outer query gives you all the rows that have that length. And it may be more than one.

查看更多
登录 后发表回答