问题
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