-- row_number()로 row별 1번~순서 매겨서 tmp1 테이블에 저장
create table tmp1 as
select (row_number() over()) as rn, col3
from
(
select distinct(b.col3) as col3
from table1 a
left join
table2 b
on a.col1 = b.col2
where a.col2='Y'
and b.col3 is not null
);
result
select * from tmp1;
rn | col3 |
1 | data1 |
2 | data2 |
3 | data3 |
'IT > SQL' 카테고리의 다른 글
[PostgrdSQL] WITH AS / CTE (0) | 2021.12.27 |
---|---|
[PostgreSQL] 마지막 한달이내 접속일자 (0) | 2021.12.27 |
[PostgreSQL] 월별,시간별 데이터 집계 (0) | 2021.12.27 |
[PostgreSQL] [limit] 분할 삭제,분할 업데이트 (0) | 2021.12.27 |
[PostgreSQL] Decode (0) | 2021.12.27 |