実行したSQL
select to_char(foo.sellday, 'yyyy') as 発売年
, round(avg(case when tandoku then foo.median else NULL end), 2) as 単独med
, count(case when tandoku then foo.game_id else NULL end) as 単独cnt
/* , string_agg(case when tandoku then foo.gamename||'('||foo.median||')' else NULL end, ' / ' order by foo.median desc) as 単独game*/
, round(avg(case when tandoku then NULL else foo.median end), 2) as 複数med
, count(case when tandoku then NULL else foo.game_id end) as 複数cnt
/* , string_agg(case when tandoku then NULL else foo.gamename||'('||foo.median||')' end, ' / ' order by foo.median desc) as 複数game*/
, round(avg(case when coalesce(foo.median, 0) <= 70 then NULL when tandoku then foo.median else NULL end), 2) as 単独70med
, count(case when coalesce(foo.median, 0) <= 70 then NULL when tandoku then foo.game_id else NULL end) as 単独70cnt
/* , string_agg(case when coalesce(foo.median, 0) <= 70 then NULL when tandoku then foo.gamename||'('||foo.median||')' else NULL end, ' / ' order by foo.median desc) as 単独70game*/
, round(avg(case when coalesce(foo.median, 0) <= 70 then NULL when tandoku then NULL else foo.median end), 2) as 複数70med
, count(case when coalesce(foo.median, 0) <= 70 then NULL when tandoku then NULL else foo.game_id end) as 複数70cnt
/* , string_agg(case when coalesce(foo.median, 0) <= 70 then NULL when tandoku then NULL else foo.gamename||'('||foo.median||')' end, ' / ' order by foo.median desc) as 複数70game*/
from (
select ttt.game_id
, ttt.gamename
, ttt.brandname
, ttt.sellday
, ttt.median
, ttt.count
, case when count(ss.creater) = 1 then TRUE else FALSE end::boolean as tandoku
from toukei_temp_table as ttt
, shokushu as ss
where ttt.game_id = ss.game
and ttt.model = 'PC'
and ttt.coterie is NULL
and ss.shubetu = 2/*職種:ライター*/
and ttt.game_id in (
select ig.game
from itemlist as il
, item_game as ig
where il.id = ig.item
and fixedprice > 7000
)
group by ttt.game_id
, ttt.gamename
, ttt.brandname
, ttt.sellday
, ttt.median
, ttt.count
) as foo
group by to_char(foo.sellday, 'yyyy')
order by 発売年 desc