안녕하세요. 첫 가입부터 질문이라 죄송합니다..
기간별로 값을 뽑아내려고 하는데요 <- 제가 써놓고도 무슨말인지 모르겠습니다. 그래서 예로 적습니다
TABLE A | |
2013.01.01 | A |
2013.09.01 | B |
2014.04.01 | C |
TABLE B |
2013.08.30 |
2013.08.31 |
2013.09.01 |
2014.03.31 |
2014.04.01 |
2014.04.02 |
이런값들이 들어가 있을때
2013.08.30 | A |
2013.08.31 | A |
2013.09.01 | B |
2014.03.31 | B |
2014.04.01 | C |
2014.04.02 | C |
이렇게 생성되도록 할수 있나요?
아래는 임시테이블로 테스트 할수 있게 간단히 만들어 본겁니다 !
이 중생 구제해 주옵소서.
----------------------------------------------------------
create table #temp_a
( a_date datetime, a_text varchar )
create table #temp_b
( b_date datetime )
insert #temp_a
select '2013.01.01' ,'A'
union
select '2013.09.01' ,'B'
union
select '2014.04.01' ,'C'
insert #temp_b
select '2013.08.30'
union
select '2013.08.31'
union
select '2013.09.01'
union
select '2013.09.02'
Comment 2
-
항해자™
2014.02.24 16:35
create table #temp_a(a_date datetime,a_text varchar)create table #temp_b(b_date datetime)insert into #temp_aselect '2013.01.01', 'A' union allselect '2013.09.01', 'B' union allselect '2014.04.01', 'C'truncate table #temp_binsert into #temp_bselect '2013.08.30' union allselect '2013.08.31' union allselect '2013.09.01' union allselect '2014.03.31' union allselect '2014.04.01' union allselect '2014.04.02'declare @v_text char(1)select top 1 @v_text = a_textFROM #temp_aorder by a_dateselecta.b_date,ISNULL(ISNULL(LAG(b.a_text,1,NULL) OVER (ORDER BY a.b_date),b.a_text),@v_text)from #temp_b as aleft join #temp_a as bon b.a_date = a.b_dateorder by a.b_date -
아루카스
2014.02.24 17:45
음 제가 sql 2008 R2인데 LAG 함수를 인식을 못하네요 다른 설정이 있을까요?