日期:2014-05-17 浏览次数:20868 次
-- 用GROUP BY就可以了吧
select sum(TJA),sum(SBA),sum(TJB),sum(SBB),,,, MONTH,CITY
where MONTH={0}
group by month, city
order by month,CITY
create table tb
(
ID varchar2(4),
SBA number,
TJA number,
SBB number,
TJB number,
MONTH varchar2(6),
CITY varchar2(5)
);
insert into tb(ID,SBA,TJA,SBB,TJB,MONTH,CITY)values('0001',1,1,0,1,'201301','CITYA');
insert into tb(ID,SBA,TJA,SBB,TJB,MONTH,CITY)values('0002',1,0,1,0,'201301','CITYA');
insert into tb(ID,SBA,TJA,SBB,TJB,MONTH,CITY)values('0003',1,1,0,1,'201301','CITYB');
insert into tb(ID,SBA,TJA,SBB,TJB,MONTH,CITY)values('0004',1,0,1,0,'201301','CITYB');
select
sum(SBA) as SBA,
sum(TJA) as TJA,
sum(SBB) as SBB,
sum(TJB) as TJB,
MONTH,
CITY
from
tb
group by
MONTH,
CITY;
/*
SBA TJA SBB TJB MONTH CITY
---------------------- ---------------------- ---------------------- ---------------------- ------ -----
2 1 1 &nb