Home » SQL & PL/SQL » SQL & PL/SQL » Question on sum up of 2 columns that created by "decode" function
Question on sum up of 2 columns that created by "decode" function [message #197083] Mon, 09 October 2006 22:41 Go to next message
pcgame4u
Messages: 14
Registered: July 2006
Junior Member
SELECT BILLED_EVENT_CODE,SERVICE_ID,
	sum(decode(entitlement_flag,'A',1,0)) flag_A,
	sum(decode(entitlement_flag,'P',1,0)) flag_P,
	sum(decode(entitlement_flag,'C',1,0)) flag_C
FROM BUE.BUE_BILLED_IP_SDR_00008053
WHERE ENTITLEMENT_FLAG IN('A','P','C')
GROUP BY BILLED_EVENT_CODE,SERVICE_ID;

now i want to sum 2 columns, for examples <flag_A && flag_P>
then how can i do this in effective way?

thanks all brothers help.
Re: Question on sum up of 2 columns that created by "decode" function [message #197087 is a reply to message #197083] Mon, 09 October 2006 22:54 Go to previous messageGo to next message
pcgame4u
Messages: 14
Registered: July 2006
Junior Member
pcgame4u wrote on Mon, 09 October 2006 22:41

SELECT BILLED_EVENT_CODE,SERVICE_ID,
	sum(decode(entitlement_flag,'A',1,0)) flag_A,
	sum(decode(entitlement_flag,'P',1,0)) flag_P,
	sum(decode(entitlement_flag,'C',1,0)) flag_C
FROM BUE.BUE_BILLED_IP_SDR_00008053
WHERE ENTITLEMENT_FLAG IN('A','P','C')
GROUP BY BILLED_EVENT_CODE,SERVICE_ID;

now i want to sum 2 columns, for examples <flag_A && flag_P>
then how can i do this in effective way?

thanks all brothers help.


i have try and here is my result.

SELECT BILLED_EVENT_CODE,SERVICE_ID,
	sum(decode(entitlement_flag,'A',1,0)) +
	sum(decode(entitlement_flag,'P',1,0)) flag_AP,
	sum(decode(entitlement_flag,'C',1,0)) flag_C
FROM BUE.BUE_BILLED_IP_SDR_00008053
WHERE ENTITLEMENT_FLAG IN('A','P','C')
GROUP BY BILLED_EVENT_CODE,SERVICE_ID;

[Updated on: Mon, 09 October 2006 22:55]

Report message to a moderator

Re: Question on sum up of 2 columns that created by "decode" function [message #197116 is a reply to message #197087] Tue, 10 October 2006 02:05 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Does what you've tried not work? Looks ok to me.
You could try
SELECT BILLED_EVENT_CODE,SERVICE_ID,
	sum(decode(entitlement_flag,'A',1,'P',1,0)) flag_AP,
	sum(decode(entitlement_flag,'C',1,0)) flag_C
FROM BUE.BUE_BILLED_IP_SDR_00008053
WHERE ENTITLEMENT_FLAG IN('A','P','C')
GROUP BY BILLED_EVENT_CODE,SERVICE_ID;
Previous Topic: Problem r'ing place of inserting
Next Topic: Questions on nested select statements
Goto Forum:
  


Current Time: Sun Dec 04 22:53:39 CST 2016

Total time taken to generate the page: 0.08560 seconds