來源: PTT DATABASE版

 

 

 

create table testtable (c1 varchar2(5),c2 varchar2(5),c3 varchar2(5),c4 number);

insert into testtable values('c','h','正',9);

insert ....

select * from testtable;

*************
select c1,c2,sum(case when c3='正' then c4*1 when c3='負' then c4*-1 end)"總和" from testtable group by c1,c2 order by c1;

*************

*利用 case 判斷類別正負,進而轉換數量(+-)

*可以利用GROUP BY 2個欄位來達成column1 2的效果 

 

 

 

文章標籤
全站熱搜
創作者介紹
創作者 to52016 的頭像
to52016

Eason [資料科學//Python學習/資料庫] & [拍片&剪片]

to52016 發表在 痞客邦 留言(0) 人氣(11)