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
댓글 영역