oracle中欄位分別求和,oracle中欄位分別求和

時間 2021-10-27 04:38:38

1樓:

可以通過sum case函式來實現,參考如下select sum(case zbxpbh when '3032' then 1 else 0 end) suma,

sum(case zbxpbh when '0000' then 1 else 0 end) sumb,

sum(case zbxpbh when '3032' then 0 when '0000' then 0 else 1 end) sumc

from t

2樓:憶似血中劍

select sum(case when zbxpbh ='3032' then 1 else 0 end) suma,

sum(case when zbxpbh = '0000' then 1 else 0 end) sumb,

sum(case when zbxpbh in ('3032' '0000') then 0 else 1 end) sumc

from t

3樓:匿名使用者

select count(*) from a where 你的字段=『值』

select sum(需要統計的字段) from a where 你的字段=『值』 group by 分組

oracle 多個字段查詢其中乙個字段求和

4樓:匿名使用者

資料create table test

(fbm int,

fxm varchar(10),

ftem varchar(10),

fje int);

insert into test values (1,'張三','吃飯',20);

insert into test values (1,'張三','睡覺',21);

insert into test values (1,'張三','起床',22);

insert into test values (4,'落筆','跑步',23);

insert into test values (5,'蘿蔔','運動',24);

commit;

語句:select t.* from

(select * from test

union all

(select fbm,fxm,'合計',sum(fje) fje from test group by fbm,fxm)) t

order by fbm,case when ftem ='合計' then 1 else 0 end;

結果:這樣?

oracle中列中的資料求和

5樓:匿名使用者

select sum(a) from 表名; 這個語句,要達到你們目的,除非你這個表中只有這三行資料。

6樓:匿名使用者

select sum(a) from 表名

oracle中如何對已求出和的字段再求和

7樓:匿名使用者

1. 如果,要對每乙個 a.lotid 都計算一次各類的彙總值的話,只需在select a.lotid,後再加一子句即可,加後為:

select a.lotid,

sum(case when a.line in ('bml','blu','grn','red','rpl','ocl','ial','ibl','anl','psl','fil') then a.times else 0 end) as all_class,

sum(decode(a.line, 'bml', a.times)) as bml,

sum(decode(a.line, 'blu', a.times)) as blu,

sum(decode(a.line, 'grn', a.times)) as grn,

sum(decode(a.line, 'red', a.times)) as red,

sum(decode(a.line, 'rpl', a.times)) as rpl,

sum(decode(a.line, 'ocl', a.times)) as ocl,

sum(decode(a.line, 'ial', a.times, 'ibl', a.times)) as ito,

sum(decode(a.line, 'anl', a.times)) as anl,

sum(decode(a.line, 'psl', a.times)) as psl,

sum(decode(a.line, 'fil', a.times)) as fil

from (select t.oper_id as line,

substr(t.lot_id, 1, 3) as lotid,

(to_date(t.end_timestamp, 'yyyy-mm-dd hh24:mi:ss') -

to_date(t.start_timestamp, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 as times

from report.st_abnormal t

where error_second_code in ('n002', 'b001', 'b002')

and t.txn_date >= '2014-03-01'

and t.txn_date < = '2014-03-31') a

group by a.lotid

2. 如果要對所有的 a.lotid計算所有類別的彙總的話,可用下面語句(較好):

select sum(case when a.line in ('bml','blu','grn','red','rpl','ocl','ial','ibl','anl','psl','fil') then a.times else 0 end) as all_sum

from (select t.oper_id as line,

substr(t.lot_id, 1, 3) as lotid,

(to_date(t.end_timestamp, 'yyyy-mm-dd hh24:mi:ss') -

to_date(t.start_timestamp, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 as times

from report.st_abnormal t

where error_second_code in ('n002', 'b001', 'b002')

and t.txn_date >= '2014-03-01'

and t.txn_date < = '2014-03-31') a

也可在你的語句外再套一層(此法效率不高,不建議):

select sum(bml+blu+grn+red+rpl+ocl+ito+anl+psl+fil) as all_sum

from

(select a.lotid,

sum(decode(a.line, 'bml', a.times)) as bml,

sum(decode(a.line, 'blu', a.times)) as blu,

sum(decode(a.line, 'grn', a.times)) as grn,

sum(decode(a.line, 'red', a.times)) as red,

sum(decode(a.line, 'rpl', a.times)) as rpl,

sum(decode(a.line, 'ocl', a.times)) as ocl,

sum(decode(a.line, 'ial', a.times, 'ibl', a.times)) as ito,

sum(decode(a.line, 'anl', a.times)) as anl,

sum(decode(a.line, 'psl', a.times)) as psl,

sum(decode(a.line, 'fil', a.times)) as fil

from (select t.oper_id as line,

substr(t.lot_id, 1, 3) as lotid,

(to_date(t.end_timestamp, 'yyyy-mm-dd hh24:mi:ss') -

to_date(t.start_timestamp, 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 as times

from report.st_abnormal t

where error_second_code in ('n002', 'b001', 'b002')

and t.txn_date >= '2014-03-01'

and t.txn_date < = '2014-03-31') a

group by a.lotid

)請根據需要,具體斟酌

oracle列求和?

8樓:匿名使用者

測試資料

create table test

(mount int,

unit varchar2(10));

insert into test values (100,'ml');

insert into test values (100,'ml');

insert into test values (1,'u');

insert into test values (200,'ml');

insert into test values (1,'u');

insert into test values (200,'ml');

執行select replace(wm_concat(t.mount||unit),',','+')

from

(select sum(mount) mount,unit from test where unit in ('ml','u') group by unit order by unit desc) t

結果如果執行不了,把wm_concat改換成sys.wm_concat

9樓:匿名使用者

上面回答的太好了,**並茂

oracle中多個字段怎麼進行求和?請舉例說明

10樓:匿名使用者

什麼意思?字段求和直接加不就行了?

select 欄位a+欄位b from 表

oracle求和問題

select sum a.je as jehj,a.bh as bh,to char a.fkrq q,yyyymm as fkrq from xsb a where to char a.fkrq q,yyyymm to char add months sysdate,2 yyyymm and a....

oracle資料庫怎麼把表中的欄位按規律拆

1 首先需要sys或system許可權操作 2 查詢需要更改表的id select object id from all objects where owner ithome and object name test 1234注 ithome為使用者,test是要更改的表,表名要大寫3 通過id查出...

求助 c查詢oracle資料庫中的表的字段內容並按列顯示在listbox中

九州樹 protected void button1 click object sender,eventargs e dr.close dbc.dispose conn.close string strselect select distinct 欄位名 from test 查詢字串 dataset...