日期:2014-05-16 浏览次数:20683 次
create table t1
(
ht_date char(4),
ht_gross decimal(4,2),
ht_count int,
ht_name char(4)
)
insert into t1
select '2010',20.00,30,'aa'
union all select '2011',21.00,31,'bb'
union all select '2012',23.00,33,'cc'
union all select '2013',25.00,31,'dd'
select * from t1
select ht_name,ht_count ,sum(case when ht_date='2010' then ht_gross else 0 end) n2010
,
sum(case when ht_date='2011' then ht_gross else 0 end) n2011,
sum(case when ht_date='2012' then ht_gross else 0 end) n2011,
sum(case when ht_date='2013' then ht_gross else 0 end) n2011
from t1
group by ht_name,ht_count