sql - oracle sum column as a new column in existing table -
i have below query in oracle db:
select 1 not_ok, case when pplp_name='ppl_ch_invoice' case when ( to_char(start_time, 'dd')<='06' , to_char(start_time, 'dd')=to_char(end_time, 'dd') ) 1 else 0 end else case when ( to_char(start_time, 'dd')='01' , to_char(end_time, 'dd')='01' ) 1 else 0 end end status, pplp_name,successful_rows,start_time,end_time general_statistics.pplp_load_genstat2
for example outputs:
not_ok status pplp_name successful_rows start_time end_time 1 0 ppl_invoice 11598133 27/3/2013 12:34:59 pm 27/3/2013 1:23:07 pm 1 0 ppl_invoice 4883282 29/3/2013 11:14:10 29/3/2013 11:35:53 1 1 ppl_invoice 16634203 1/4/2013 5:32:28 1/4/2013 6:15:21 1 0 ppl_invoice 16659489 26/4/2013 9:22:38 26/4/2013 10:25:28 1 0 ppl_invoice 18192538 26/4/2013 11:02:47 26/4/2013 11:54:43 1 0 ppl_invoice 15900000 26/4/2013 1:12:59 pm 26/4/2013 2:12:21 pm 1 1 ppl_invoice 16168904 1/5/2013 12:51:37 pm 1/5/2013 2:22:21 pm 1 1 ppl_invoice 16414332 1/6/2013 3:37:04 1/6/2013 4:18:38 1 1 ppl_invoice 16112065 1/7/2013 8:17:55 1/7/2013 9:38:15 1 1 ppl_invoice 17731276 1/8/2013 3:50:51 1/8/2013 4:41:09 1 0 ppl_invoice 17731276 31/8/2013 3:59:38 31/8/2013 4:50:42 1 1 ppl_invoice 17572735 1/9/2013 2:59:29 pm 1/9/2013 3:46:47 pm 1 1 ppl_invoice 17820708 1/10/2013 8:36:01 1/10/2013 10:16:01 1 1 ppl_invoice 17008019 1/11/2013 3:59:32 1/11/2013 4:54:17 1 1 ppl_invoice 17070125 1/12/2013 4:04:20 1/12/2013 4:52:03
how possible create 2 columns in above select statement, 1 sum of status , 1 sum of not_ok ?
thanks in advance!
as far understood you, think can try:
select b.* , sum(b.not_ok) on (partition to_char(start_time,'mm') ) tot_not_ok , sum(b.status) on (partition to_char(start_time,'mm')) tot_status ( select 1 not_ok, case when pplp_name='ppl_ch_invoice' case when (to_char(start_time, 'dd')<='06' , to_char(start_time, 'dd')=to_char(end_time, 'dd') ) 1 else 0 end else case when ( to_char(start_time, 'dd')='01' , to_char(end_time, 'dd')='01' ) 1 else 0 end end status, pplp_name, successful_rows, start_time,end_time general_statistics.pplp_load_genstat2 ) b
Comments
Post a Comment