sql⾏转列:越简单越好下图为需求:
sql脚本:
--oracle 10g
错过的美丽create table tbArea(id number,product varchar2(50),area varchar2(50),num number);
雨中漫步2
inrt into tbArea(id,product,area,num)
lect 1,'A','华北',1 from dual union
感恩素材
lect 2,'A','华北',2 from dual union
lect 3,'A','华东',3 from dual union
张景富lect 4,'A','华东',4 from dual union描写大自然的作文
电子简历怎么做
lect 5,'B','华南',1 from dual union
lect 6,'B','东北',2 from dual union
伤情的歌lect 7,'B','西南',3 from dual;
lect * from tbArea;
---⽜b的sql语句:
--⽅法1:两次group by
工作要求怎么写lect product 商品,sum(type) 分布地区,sum(num) 数量 from (
lect product ,area ,sum(num) num,1 type from tbArea
group by product,area
)group by product;
--⽅法2:distinct
lect product 商品,count(distinct(area)) 分布地区,sum(num) 数量 from tbArea group by product;
--drop table tbArea;