쿼리에 도움을 구합니다. ㅠㅠ
WITH t AS
(
SELECT '0001' r_no, to_date('20000105','yyyymmdd') r_date, 'N' status FROM dual
UNION ALL SELECT '0001' r_no, to_date('20010501','yyyymmdd') r_date, 'N' status FROM dual
UNION ALL SELECT '0001' r_no, to_date('20051205','yyyymmdd') r_date, 'Y' status FROM dual
UNION ALL SELECT '0001' r_no, to_date('20060130','yyyymmdd') r_date, 'N' status FROM dual
UNION ALL SELECT '0002' r_no, to_date('20000101','yyyymmdd') r_date, 'N' status FROM dual
UNION ALL SELECT '0002' r_no, to_date('20080830','yyyymmdd') r_date, 'Y' status FROM dual
UNION ALL SELECT '0003' r_no, to_date('20050513','yyyymmdd') r_date, 'Y' status FROM dual
UNION ALL SELECT '0003' r_no, to_date('20100105','yyyymmdd') r_date, 'Y' status FROM dual
UNION ALL SELECT '0003' r_no, to_date('20130130','yyyymmdd') r_date, 'N' status FROM dual
UNION ALL SELECT '0004' r_no, to_date('19991202','yyyymmdd') r_date, 'N' status FROM dual
UNION ALL SELECT '0004' r_no, to_date('20040303','yyyymmdd') r_date, 'N' status FROM dual
UNION ALL SELECT '0004' r_no, to_date('20050110','yyyymmdd') r_date, 'N' status FROM dual
UNION ALL SELECT '0004' r_no, to_date('20100705','yyyymmdd') r_date, 'Y' status FROM dual
UNION ALL SELECT '0004' r_no, to_date('20111227','yyyymmdd') r_date, 'N' status FROM dual
UNION ALL SELECT '0004' r_no, to_date('20120305','yyyymmdd') r_date, 'Y' status FROM dual
)
select * from t
order by r_no, r_date;
R_NO : 등록자
R_DATE : 등록일
STATUS : 접속상태 (Y-성공, N-실패)
의 기초 데이터로 개인별 접속시도 횟수를 구하고 싶습니다.
(등록자가 바뀌거나 접속성공후에는 0으로 리셋)
등록자, 등록일, 접속상태, 이전접속시도횟수
------------------------------------------------
0001, 2000/01/05 00:00:00, N, 0
0001, 2001/05/01 00:00:00, N, 1
0001, 2005/12/05 00:00:00, Y, 2
0001, 2006/01/30 00:00:00, N, 0
0002, 2000/01/01 00:00:00, N, 0
0002, 2008/08/30 00:00:00, Y, 1
0003, 2005/05/13 00:00:00, Y, 0
0003, 2010/01/05 00:00:00, Y, 0
0003, 2013/01/30 00:00:00, N, 0
0004, 1999/12/02 00:00:00, N, 0
0004, 2004/03/03 00:00:00, N, 1
0004, 2005/01/10 00:00:00, N, 2
0004, 2010/07/05 00:00:00, Y, 3
0004, 2011/12/27 00:00:00, N, 0
0004, 2012/03/05 00:00:00, Y, 1