MAX쿼리 뭔의드립니다. 0 2 981

by DB초보자입니다 [SQL Query] [2019.06.19 10:06:22]


with TMP_T as
(
select 1 as no,'T' as nm from dual
union all
select 1 as no,'A' as nm from dual
union all
select 3 as no,'B' as nm from dual
union all
select 4 as no,'C' as nm from dual
union all
select 5 as no,'D' as nm from dual
union all
select 6 as no,'E' as nm from dual
)
select (SELECT MAX(NO) +1 from TMP_T),NM
from TMP_T
where no = 1

제가 원하는 결과는

7 T

8 A 라는 결과를 원하는데

위의 쿼리에서 조회된느값은

7 T

7 A로 나오네요 어덯게 해야될까요?

by 르매 [2019.06.19 12:51:13]

이런 식일까요?

with TMP_T as
(
select 1 as no,'T' as nm from dual
union all
select 1 as no,'A' as nm from dual
union all
select 3 as no,'B' as nm from dual
union all
select 4 as no,'C' as nm from dual
union all
select 5 as no,'D' as nm from dual
union all
select 6 as no,'E' as nm from dual
)
select (SELECT MAX(no) from TMP_T) + ROWNUM, NM
from TMP_T
where no = 1
order by no;

 


by DB초보자입니다 [2019.06.19 13:35:06]

위에같이 하니깐 간단하게 되네요ㅠㅠ너무 어렵게 생각했나봅니다

감사합니다.

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입