with t as
(select b.calendar_month_desc, c.promo_category, a.amount_sold
from sh.sales a
left join sh.times b
on a.time_id = b.time_id
left join sh.promotions c
on a.promo_id = c.promo_id
where promo_category in ('NO PROMOTION', 'internet', 'post'))
select *
from t
pivot (sum(amount_sold) for promo_category in('NO PROMOTION' "NO PROMOTION",
'internet' "internet",
'post' "post"));
对这几个表不太熟悉,amount_sold 这个字段我就当做销售额了。