아마 대부분의 DBMS와 함께 작동하는 버전이 될 것입니다 :
select add_1, add_2, add_3
from T
where length(trim(add_1)) + length(trim(add_2)) + length(trim(add_3))
= (select max(len)
from (
select
length(trim(add_1)) + length(trim(add_2)) + length(trim(add_3)) as len
from T
)
)
를 사용할 수 add_n가 널 (NULL)이 될 수있는 경우 예 :
coalesce(trim(add_1),'')
이 그것을 처리합니다.
DBMS가 CTE (Common Table Expressions)를 지원하는 경우이를 사용하는 것이 더 효율적일 수 있습니다. 뭔가 같은 :
with cte (add_1,add_2,add_3,len) as (
select add_1,add_2,add_3
, length(trim(add_1))+length(trim(add_3))+length(trim(add_3)) from T
)
select add_1,add_2,add_3
from cte
where len = (select max(len) from cte)
당신의 DBMS는 ROW_NUMBER 등의 분석 기능을 지원하는 경우 또 다른 옵션은 다음과 같습니다
select add_1,add_2,add_3
from (
select add_1,add_2,add_3
, row_number() over (
order by length(trim(add_1))+length(trim(add_3))+length(trim(add_3)) desc
) as rn
from t
) where rn = 1
또는 수
select add_1,add_2,add_3
from T
order by length(trim(add_1))+length(trim(add_3))+length(trim(add_3)) desc
fetch first 1 rows only
+1이 좋은,하지만 좀 더 필요 그가 실제 길이가 아닌 주소를 원하는대로 작업하십시오. – CodeBird
@CodeBird 추가 된 답변을 확인하십시오. – TechDo
그것은 그것을 분류했다. 모든 도움을 주셔서 대단히 감사합니다. 많은 좋은 해결책과 새로운 사용자로부터의 긴 대답에 대해 많이 aprpeciated – user3592268