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
(
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
20.00 21.00 23.00 25.00 (HT_GROSS)
30 31 33 35 (HT_COUNT)
aa bb cc dd (HT_NAME一个列一个属性吧