SQL select the longest char

孤者浪人 提交于 2019-12-12 05:37:37

问题


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 ?

回答1:


select top (1) * from customer order by len(adresse) desc;



回答2:


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.




回答3:


SELECT address FROM customer WHERE length(address) = (SELECT max(length(address)) FROM customer)



回答4:


try this:

select max(len(adresse)) from customer 


来源:https://stackoverflow.com/questions/12365953/sql-select-the-longest-char

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!