postgres=# create view clubgroup(name,age,address,flag,id,clubname)
as
select * from grouplist as g left outer join clublist as c on g.flag=c.id ;
postgres=# select
postgres-# sum(case when(age between 20 and 29) and (clubname='tennis') then 1 else 0 end)as hoge1,
postgres-# sum(case when(age between 30 and 39) and (clubname='music') then 1 else 0 end)as hoge2,
postgres-# sum(case when(age between 40 and 49) and (clubname='baseball') then 1 else 0 end)as hoge3
postgres-# from clubgroup ;
hoge1 | hoge2 | hoge3
-------+-------+-------
8 | 7 | 1
select * from flaglist1 as f
left outer join clublist as c
on f.flag = c.id ;