블로그 이미지
010-9967-0955 보미아빠

카테고리

보미아빠, 석이 (500)
밥벌이 (16)
싸이클 (1)
일상 (1)
Total
Today
Yesterday

달력

« » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

공지사항

최근에 올라온 글



--1. http://www.postman.pe.kr/zipcode/ 에서 3번 다운로드
--2. excel 에서 csv 로 변환 후 db insert

if object_id('tblx') is not null
drop table tblx
go

create table tblx
(
ZIPCODE varchar(1000)
,SIDO varchar(1000)
,GUGUN varchar(1000)
,DONG varchar(1000)
,RI varchar(1000)
,ST_BUNJI varchar(1000)
,ED_BUNJI varchar(1000)
,SEQ varchar(1000)
)
go

BULK INSERT l.dbo.[TBLx]
FROM '\\127.0.0.1\c$\db1\zipcode_20110311.txt'
WITH
(
FIELDTERMINATOR = ',',
TABLOCK,
FIRSTROW =2
)
go

delete from tblx where seq is null
go

--3. 모의 데이터 삽입
if object_id('tbly') is not null
drop table tbly
go

create table tbly
(idx int identity(1,1)
,h_address varchar(1000)
)
go

insert into tbly values ('서울특별시 강남구 논현1동 21번지')
insert into tbly values ('대구시 동구 신암4동 139번지')
insert into tbly values ('경기도 용인시 기흥구 중동 참솔마을 109동')
insert into tbly values ('경기 용인 기흥 중동 참솔마을')
insert into tbly values ('대구동구신암3동 어쩔시구리')
insert into tbly values ('이상한나라의 엘리스')
go

select top 3 * from tblx order by cast(seq as int)
select * from tbly

-- 원하는 데이터         
select sido, gugun, count(*) cnt
  from (select idx, h_address, zipcode, sido, gugun
    from tbly a
   cross apply (select top 1 *
      from tblx
        where a.h_address like +'%'+left(SIDO,2)+'%'+'%'+left(GUGUN,2)+'%') b ) a
 group by sido, gugun
go

-- 오류 데이터

select a.*
  from tbly a
  left join (select idx, h_address, zipcode, sido, gugun
     from tbly a
    cross apply (select top 1 *
       from tblx
       where a.h_address like +'%'+left(SIDO,2)+'%'+'%'+left(GUGUN,2)+'%') b ) b
    on a.idx = b.idx
 where b.idx is null

Posted by 보미아빠
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함