Sum but cases
hi i'm using oracle 10g r2
i have a data like this
ITEM-------------LINETYPE--------------DEBIT------------------CREDIT
A010-------------LIABILITY---------------0---------------------------3000
A010--------------LIABILITY-------------0----------------------------2000
A010--------------TAX----------------------0---------------------------200
A010----------------CHARGE---------------5200-----------------------0I want to show my data like this
ITEM-------------LINETYPE--------------DEBIT------------------CREDIT
A010-------------LIABILITY---------------0---------------------------5000
A010--------------TAX----------------------0---------------------------200
A010----------------CHARGE---------------5200-----------------------0I WANT to sum but if linetype = 'LIABILITY' how to achieved this by query?
If some of the linetypes other than 'LIABILITY' did have multiple rows for the same item, and you didn't want to combine them, then you could add a CASE expression to the end of GROUP BY clause, somthing like this:
YES frank i want to like this
in case which column i have to set primary key
if my data like this
ITEM---------LINE_TYPE-----------DR---------------CR
B1---------------LIABILITY-----------0-----------------5000
B1---------------LIABILITY-----------0------------------2000
B1----------------TAX------------------0------------------1000
B1---------------TAX------------------0---------------------800
B1---------------CHARGE----------5000
B1---------------CHARGE-----------3800i want like this
ITEM---------LINE_TYPE-----------DR---------------CR
B1---------------LIABILITY-----------0-----------------7000
B1----------------TAX------------------0------------------1000
B1---------------TAX------------------0---------------------800
B1---------------CHARGE----------5000
B1---------------CHARGE-----------3800ONLY sum in liability case
please help
Edited by: BluShadow on 17-Oct-2011 15:43
fixed {noformat}{noformat} tags. the word "code" has to be lower case in the tags.
Similar Messages
-
2010 MacBook was repaired by Apple but case is misaligned
I can't remember why I had to take it in for service but after I got it back the case was slightly misaligned. It was off by just enough to not let me get a headphone jack in and the connection to the power adapter has been intermittent at best. When its plugged in to the power adapter, it works but the power indicator says, for the most part, "(Not Charging.)"
I know I should have returned immediately but the power problem wasn't terrible at that time and I was able to get a headphone jack in finally.
I do not want to pay for this repair...Apple would like me to.
Any suggestions?
Thanks in advance!Get a USB Audio adapter from MacAlly or Griffin Technologies.
Next time when you get a repair, inspect everything within the warranty period of the repair (which typically is 90 days). -
Combine greatest, sum, and case when
All,
I have the following view
Select table1.field1,
greatest(sum(table1.field3) - case when table1.oneorzerocolumn=1 then table1.field2 else table1.field4 end,0) as NetAbove0
from table1
group by table1.field1;
I seem to be having trouble figuring out the best way to accomplish this, though, as whenever I try to execute this query I get not a valid group by expression. How can I combine the greatest function and the aggregate sum function without creating a separate view?
Thanks in advance.
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
Edited by: 929933 on Mar 14, 2013 1:32 PM929933 wrote:
@ sb92075 would you care to elaborate on exactly what was missing?If you would care to read the link sb92075 posted you will understand by yourself:
What is particularly important in that FAQ is:
6) Tables/Indexes
7) Sample Data
8) Expected Output
9) Formatting with {noformat}{noformat} Tags
You have posted an unformatted code and did not provide proper input.
Coming to your problem the issue is quite clear. If you use a GROUP BY clause then all field which are not returned as aggregated function shall be included in the GROUP BY clause.
And this has a logic.
Your initial query (formatted in a decent way):SELECT table1.field1
, GREATEST (SUM (table1.field3)
- CASE
WHEN table1.oneorzerocolumn = 1 THEN
table1.field2
ELSE table1.field4
END, 0) AS netabove0
FROM table1
GROUP BY table1.field1;
is not correct.
The column used in the query table1.oneorzerocolumn, table1.field2 and table1.field4 are not part of the GROUP BY and not used in aggregation functions.
So how could you determine the value, i.e. table1.oneorzerocolumn, if for the same value of table1.field1 you have different values of table1.oneorzerocolumn?
You are aggregating by field1 so which value do you want to use for non aggregated columns?
Everything will be easier to understand if you can post some sample data, explain the logic you want to apply and post the expected output for the sample data you have posted.
Regards.
Al -
Hi Guys!
I am loading data from Oracle to Essbase and have a question for you.
Can i do something lika that in ODI mapiing:
CASE
WHEN (select sum(DataSource.value) from DataSource where Account like 'K410%') >= 0
THEN 'Profit'
WHEN (select sum(DataSource.value) from DataSource where Account like 'K410%') < 0
THEN 'Loss'
END
Best regards,
GrzegorzHi Greg
If you perform the aggregations and filter on the source you should be able to achieve what you want, check out the illustration below;
https://blogs.oracle.com/warehousebuilder/resource/ODI11g/odi_aggregation_illustration.jpg
This shows how to define the aggregation expressions.
Cheers
David -
I need help please with the following query.
I have a table that contains a currency, voucher, start_date and a value.
Data in the tables looks like this:
GB, 31/05/2010, A, 100
GB, 31/05/2010, B, 250
GB, 31/05/2010, A, 72
GB, 12/12/2009, A, 1000
GB, 12/12/2009, B, 72
LX, 12/05/2010, A, 90
This is where it gets complicated, I need to show the total(SUM) value when the start_date < 60 days from sysdate and also when the start_date > 61 days AND only if the voucher = A and partioned by the currency.
So, in other words I need my results like this.
GB, 31/05/2010, A, 100, *172, 0*
GB, 31/05/2010, B, 250, *0, 0*
GB, 31/05/2010, A, 72, *172, 0*
GB, 12/12/2009, A, 1000, *0, 1000*
GB, 12/12/2009, B, 72, *0, 0*
LX, 12/05/2010, A, 90, *90, 0*
The bold columns are what I need, one called less_than and one more_than.
A big big thank you and any advice I appreciate.
SPlease make a habit of posting sample data we can work with right away by using CREATE TABLE and INSERT INTO statements, or use the WITH clause as shown below:
SQL> with t as ( -- generating sample data:
2 select 'GB' currency, to_date('31/05/2010', 'dd/mm/yyyy') start_date, 'A' voucher, 100 value from dual union
3 select 'GB', to_date('31/05/2010', 'dd/mm/yyyy'), 'B', 250 from dual union
4 select 'GB', to_date('31/05/2010', 'dd/mm/yyyy'), 'A', 72 from dual union
5 select 'GB', to_date('12/12/2009', 'dd/mm/yyyy'), 'A', 1000 from dual union
6 select 'GB', to_date('12/12/2009', 'dd/mm/yyyy'), 'B', 72 from dual union
7 select 'LX', to_date('12/05/2010', 'dd/mm/yyyy'), 'A', 90 from dual
8 )
9 --
10 -- actual query:
11 --
12 select currency
13 , start_date
14 , voucher
15 , value
16 , sum(case
17 when trunc(sysdate-start_date)< 60
18 and voucher = 'A'
19 then value
20 else 0
21 end) over (partition by currency, voucher, start_date) sum_val1
22 , sum(case
23 when trunc(sysdate-start_date)> 61
24 and voucher = 'A'
25 then value
26 else 0
27 end) over (partition by currency, voucher, start_date) sum_val2
28 from t;
CU START_DAT V VALUE SUM_VAL1 SUM_VAL2
GB 12-DEC-09 A 1000 0 1000
GB 31-MAY-10 A 72 172 0
GB 31-MAY-10 A 100 172 0
GB 12-DEC-09 B 72 0 0
GB 31-MAY-10 B 250 0 0
LX 12-MAY-10 A 90 90 0
6 rows selected. -
Got my phone.. but case did not come in
I ordered my phone and it came today...I however have no case for it so i do not want to activate it and put it my purse and get it all messed up....I wish amazon would hurry up and get my case in..
My iPhone showed up at 12:07pm and my case and Zagg invisible shield arrived at 12:30pm! Still waiting on the leather belt holster however.
-
Problem in using sum with distinct in case
Hi all,
I want to use a sum function with distinct and also with case.
below is the format i am using.
Sum( distinct case when a.value='TOOL' then e.value else 0 end)
This is working but i don't get distinct records.
SO i tried using in this way
Sum( case when a.value='TOOL' then distinct e.value else 0 end)
But I am getting missing expression error.
Please help me to resolve this issue
Thanks
PriyaSTEP -2
SQL>
SQL> commit;
Commit complete.
SQL> ed
Wrote file afiedt.buf
1 Select Sum(Value)
2 From (
3 Select Distinct Case when value='TOOL'
4 then value
5 else
6 0
7 end Value
8 From Blah
9* )
SQL> /
0
ERROR at line 6:
ORA-00932: inconsistent datatypes: expected CHAR got NUMBERRegards.
Satyaki De. -
Average sum for a column in ALV tree layout
Hi,
I've trying to set an average sum for a column in an ALV tree report. In the field catalog i set the DO_SUM field to 'X' and this will do a total sum, but I can't find out how in the code to do the average sum.
Also to get round this I was going to just set a default display variant with the "average" sum option saved after i had manually selected the columns and set it to this. Problem with this is that when i re-run it, the sum comes back as a total rather than an average. I have tried setting display variants on the SAP example ALV tree programs and the same thing happens.
Does anyone know how i can get round this?
Cheers
Matt.Hi,
In addition to setting DO_SUM = 'X' you need to specify function in H_FTYPE field. It should be set to 'AVG' in your case.
ls_fielcat-do_sum = 'X'.
ls_fieldcat-h_ftype = 'AVG. -
Sql query for running sum(using aggregate)
<pre>
Table name table1 (no, amount)
insert into table1 values(1, 10) ;
insert into table1 values(2 ,-10) ;
insert into table1 values(3, -20) ;
insert into table1 values(4, -30) ;
insert into table1 values(5,40) ;
and i am expecting the result in this manner
no
sum (amount)
1
10
2
0
3
-20
4
-50
5
-10
select no,sum(amount) over(order by no) from table1;
but with this query i am getting the result in below manner
no
sum (amount)
1
10
2
20
3
40
4
70
5
110
which is not excepted result, could some one help me in getting excepted results ,could any one provide the proper query for this
</pre>h
Hi Friends,
sorry to trouble you,i did not have oracle instance installed on my machine to check the query ,
this is some test query which is some resemblance with actual query in my project
actually the requirement is like this ,this is the master table
NO amount
1 10
2 100
3 120
4 50
5 41
using some decoding function in the query the result came like this
NO decode(amount,......) quantity
1 10
2 -10
3 -20
4 -30
5 41
on this decode function i am trying to using aggregate function SUM,but in that case in stood of giving
ABS value , it is giving in proper value like below result
NO decode(amount,......) quantity aggregate sum
1 10 10
2 -10 20
3 -20 40
4 -30 70
5 41 111
but i excepted the result ABS value like below
NO decode(amount,......) quantity aggregate sum
1 10 10
2 -10 0
3 -20 -20
4 -30 -50
5 41 -9
my question is aggregate function on this decoded values have any impact on the result?
for this question your are unable to help me ,tomorrow i will get exact table structure and exact query which i am using
in my project -
When i make a pivot in Excel 2010 i can change the cell to give me AVG, MAX, MIN, not only SUM, but when i créate a pivot from a tabular model, these options are disabled, i have posted a image, with a "tabla dinámica" or dynamic table
in this case, i can see the functions that i want but when i use the tabular model as a source, the options average (promedio), is disabled.
How i can enable this functions, or are a way to créate a formula for totals and subtotals, and other formula for detail in dax?
Thanks in advance.Hi juliomrs,
SSAS Tabular model doesn't let us to modify the aggregate function from the Client side. In this case, you need to create a new measure and use the function what you want inside the SSAS Tabular model.
For more information regarding DAX functions, please see:
DAX Function Reference:
http://msdn.microsoft.com/en-us/library/ee634396.aspx
Regards,
Elvis Long
TechNet Community Support -
SUM Parenthesis - Difference???
Hi;
i just want to ask if there is any differences between calculating summuation inside the pharenthesis or not???
Example Query;
select a12.CATEGORY,
(sum(a11.COL1) / (CASE WHEN COL2=0 THEN NULL ELSE COL2 END)) SUM1,
sum((a11.COL1 / (CASE WHEN COL2=0 THEN NULL ELSE COL2 END))) SUM2
from table1 a11,
table2a12
where a11.ID = a12.ID
group by a12.CATEGORY
Which one is faster? SUM1 or SUM2 or no difference???
Note that DB is Oracle 10g.
Thanks...It makes no difference because the query won't work anyway. COL1 is aggregated but COL2 isn't...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 4 as col1, 2 as col2 from dual union all
2 select 5, 3 from dual union all
3 select 6, 0 from dual union all
4 select 7, 3 from dual)
5 --
6 select sum(col1) / (case when col2=0 then null else col2 end) as sum1
7 ,sum(col1 / case when col2=0 then null else col2 end) as sum2
8* from t
SQL> /
select sum(col1) / (case when col2=0 then null else col2 end) as sum1
ERROR at line 6:
ORA-00937: not a single-group group function -
Project Retention Sum for Customers
Hi Experts,
We have a case scenario here to revise the process of retention amount for Contract Orders. Contractually, our client, the construction company and the customer define that a certain amount of the contract value is only paid after a certain timeframe. The retention amount can be calculated using SD conditions on the contract/sales order. Now as I researched through the process, it's pretty on-the-spot for this solution to create a payment terms for retention sum and assign them to the customers related. This is being configured in OBB8.
Now my dilemma is how about the previous contracts that should have retention sum but not reflected in SAP. Are there any solution for this aside from reversing all posted documents? Since all the posted documents are 3 to 4 years late already and they still haven't came up with the solution for their retention sum yet in the system. So currently they are doing the calculation of retention amount manually but are there other solution to reflect this in SAP?
Please advise. Thank you so much for the Information.
Edited by: Cecilio Cruz II on Jun 10, 2011 4:04 AMSince the Retention Payment Terms were not used till recently, all your original Customer Outstandings would be appearing as a single Debit line item for each Invoice.
You can pass an accounting entry Debiting the Customer with your Retention payment term and Crediting the same Customer with the Payment Term of the Original Invoice. Assign the same BAseline date to both the lines. -
Minimum on rows and sums/ Summation on overral result required
Dear All,
If I have three shipments with three line items then I want to see the minimum for each key figure (in this case distance). This is becasue each shipment will not have an overall sum, but a number of shipments will have an overall total
I am trying to achieve the following result:
Shipment Item Distance
1001 10 3 miles
1001 20 3 miles
1001 subtotal 3 miles (both items go to same customer)
1002 10 5 miles
1002 subtotal 5 miles
Overall result 8 miles (this is the total distance)
I am currently using exception aggregation (set to minimum on item) and this produces the following results:
Shipment Item Distance
1001 10 3 miles
1001 20 3 miles
1001 subtotal 3 miles
1002 10 5 miles
1002 subtotal 5 miles
Overall result 3 miles
This means that the overall result is wrong in the second case (I have tried playing with the aggregation by shipment number - but this was not successful).
Would be really grateful if somebody could give me some ideas with this one,
Thanks,
RonSince you didn’t upload your excel file, I’m not quite sure what’s your source data looks like.
I don’t think this issue is caused by your formula, but I guess you really need use number 3 instead of 103 in your SUBTOTAL formula.
Anyway, please try below possible solutions for this issue.
1. Set up your formula firstly, then filter data. Rather than the other way around.
2. Select the filter range before filter. Or use advanced filter(except the row which including your formula)
3. Copy the formula to the next row, then delete the pervious formula row.
If it didn’t bring any joy. It’ll be better if you can share your workbook with us. -
SUM - SPAM/SAINT 7.3 Update using SQL2012
Hi,
I installed a SAP NW BW 7.3 in Windows Server 2012 / SQL 2012 and I'm trying to update SPAM/SAINT via SUM, but this errors occurs:
1 ETQ359 RFC Login to: System="BWD", AsHost="atlas" Nr="00", GwHost="atlas", GwService="sapgw00"
2 ETQ232 RFC Login succeeded
4 ETQ010 Date & Time: 20140527175641
1 ETQ233 Calling function module "OCS_API_DELETE_QUEUE" by RFC
1EETQ235 Call of function module "OCS_API_DELETE_QUEUE" by RFC failed (error-status "3")
2EETQ360 RFC of "OCS_API_DELETE_QUEUE" failed:
2EETQ361 code/exception : 3
2EETQ362 key : DBIF_RSQL_SQL_ERROR
2EETQ399 SQL error 515 while accessing table PAT05.
4 ETQ010 Date & Time: 20140527175641
1EETQ399 Last error code set is: RFC error system BWD nr 00 function 'OCS_API_DELETE_QUEUE' failed with code 3 key DBIF_RSQL_SQL_ERROR: SQL error 515 while accessing table PAT05.
1EETQ204 Upgrade phase "SPAMCHK_INI" aborted with severe errors ("20140527175641")
And generate these two short dumps:
1)
Category ABAP Server Resource Shortage
Runtime Errors DBIF_RSQL_SQL_ERROR
Except. CX_SY_OPEN_SQL_DB
Date and Time 27.05.2014 18:32:53
Short text
SQL error 515 while accessing table "PAT05".
What happened?
Database error text: "Cannot insert the value NULL into column
'DDIC_ACT_SUBSET', table 'BWD.bwd.PAT05'; column does not allow nulls. UPDATE
fails."
2)
Category ABAP Server Resource Shortage
Runtime Errors DBIF_RSQL_SQL_ERROR
Except. CX_SY_OPEN_SQL_DB
Date and Time 27.05.2014 18:45:59
Short text
SQL error 515 while accessing table "PATHISTORY".
What happened?
Database error text: "Cannot insert the value NULL into column 'DACT_SUBSET',
table 'BWD.bwd.PATHISTORY'; column does not allow nulls. INSERT fails."
Can anyone help me?
I didn't find any SAP note, or documentation about this problem.
Thanks!
MarcelloHi Reagan,
I read this note, but the solution is to re-install the application.
I will do this in last case.
Thanks! -
Case not coming in group by clause
Hi
I have created the following query:
select sum(receipt) , sum(LINE_NO) , case
when sum(receipt) = sum(LINE_NO) then 'F' else 'G' end from test_function;
It is working fine but i have a doubt as the case is returning some character value then why it is not included in thr group by clause.
Do case part does not come in group by if case involves some aggregates?
Pls suggestpls tell me about this.
Thanks a lot in anticipation
Maybe you are looking for
-
How to instal Safari in lion 10.7.5
I can not open Safari, in my Mac book pro, the program close, after each try, when I try to install the last Version , send me an error message " you need os 10.6", ,actually I have de I OS 10.7.5. wich version shoul I have to install?
-
How to remove the recursion from the following method
Hi All, Can u plz help me to remove the recursion from the following method. The problem here is that recursion cann't be removed easily here as there is no any end condition. hopefully waiting for the help.... Reema. private FilterStatement processC
-
I have been using Dreamweaver 8 for months on a windows xp virtualbox. Today outof the blue i get an error message that says "A problem was detected with your application. Please reinstall this software to correct the problem" The title bar of the di
-
SWF file contains ref. to local dir structure
Newbie here; sorry. Flash CS4 Professional, ver. 10 Am creating a simple flash video to get my feet wet. In the process, I am drowning. I created the video with Flash (ActionScript 3.0) by inserting a player object, and specifying a f4v source that I
-
Hi I have a csv file like this... co1,col2,col3,col4 col1,col2,col3,col4 I want to skip the data in the column 1. ie., col1 and load only col2,col3 and col4 Can i do this in sql*loader. I am on 10.2.0.4 THX Sunil