日期:2014-05-17 浏览次数:21170 次
with t as ( select 销售年, 销售月, sum(金额) 月金额 from sales group by 销售年, 销售月 ) select 销售年, min(月金额), max(月金额) from t group by 销售年;
------解决方案--------------------
with t as (
select 销售年, min(销售月) 最小月份, max(销售月) 最大月份 from sales group by 销售年
)
select t.销售年,
(select sum(金额) from sales where sales.销售年=t.销售年 and sales.销售月=t.最小月份) 最小月份的金额,
(select sum(金额) from sales where sales.销售年=t.销售年 and sales.销售月=t.最大月份) 最大月份的金额 from t;