상세 컨텐츠

본문 제목

회원분포 현황(연령별)

청강컴정/09DataBase중간고사

by luckey 2009. 4. 21. 17:27

본문

declare @tempTable table(visitCnt int, memCnt int)
declare @i int
set @i = 0
while(@i < 6)
begin
 insert into @tempTable
 select sum(cnt), count(*) from
 (
 select sn, sum(visit_count_day) as cnt, year(getdate()) - subString(birthday, 1, 4) as age from member as mb
 inner join member_visit as mv
 on mb.sn = mv.fk_member
 group by sn, birthday
 ) jj
 where age between
 case @i
  when 0 then 0
  when 1 then 13
  when 2 then 19
  when 3 then 30
  when 4 then 40
  else 50 end 
 and
 case @i
  when 0 then 12
  when 1 then 18
  when 2 then 29
  when 3 then 39
  when 4 then 49
  else 100 end
 set @i = @i + 1
end
select * from @tempTable

관련글 더보기

댓글 영역