SQL> desc test_aa;
Name Type Nullable Default Comments
---- ----------- -------- ------- --------
NO NUMBER
TYPE VARCHAR2(4) Y
QUAN NUMBER Y SQL> select * from test_aa; NO TYPE QUAN
---------- ---- ----------
11 aa 100
22 bb 200
33 cc 300
44 dd 200
55 aa 200
66 aa 300
77 cc 100
88 dd 5008 rows selectedSQL> select no,decode(type,'aa',quan) aa,decode(type,'bb',quan) bb,decode(type,'cc',quan) cc,decode(type,'dd',quan) dd,decode(type,'aa',quan,0)+decode(type,'bb',quan,0)+decode(type,'cc',quan,0)+decode(type,'dd',quan,0) 合计 from test_aa; NO AA BB CC DD 合计
---------- ---------- ---------- ---------- ---------- ----------
11 100 100
22 200 200
33 300 300
44 200 200
55 200 200
66 300 300
77 100 100
88 500 5008 rows selected
Name Type Nullable Default Comments
---- ----------- -------- ------- --------
NO NUMBER
TYPE VARCHAR2(4) Y
QUAN NUMBER Y SQL> select * from test_aa; NO TYPE QUAN
---------- ---- ----------
11 aa 100
22 bb 200
33 cc 300
44 dd 200
55 aa 200
66 aa 300
77 cc 100
88 dd 5008 rows selectedSQL> select no,decode(type,'aa',quan) aa,decode(type,'bb',quan) bb,decode(type,'cc',quan) cc,decode(type,'dd',quan) dd,decode(type,'aa',quan,0)+decode(type,'bb',quan,0)+decode(type,'cc',quan,0)+decode(type,'dd',quan,0) 合计 from test_aa; NO AA BB CC DD 合计
---------- ---------- ---------- ---------- ---------- ----------
11 100 100
22 200 200
33 300 300
44 200 200
55 200 200
66 300 300
77 100 100
88 500 5008 rows selected
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货