Picking a Max value row out of a group of rows.
Hi,
I'm using Oracle 10.2.0.4.0
For some reason I can't come up with a way to pick out a simple row that contains the max date value out of a group of sub group of rows. The following rows are one group of the result of a complex view ordered by ACCOUNT_NUMBER. I'm just showing the first group for Demo Purposes.
CUSTOMER_NAME ACCOUNT_NUMBER BOOKED_DATES OUTSTANDING_APPROVALS BOOKED_NOT_BILLED SALES
ABC company, LLC 114943 05/22/2008 11:17:05 100,072.43 100,072.43
ABC company, LLC 114943 06/30/2008 15:12:29 129,956.00 129,956.00
ABC company, LLC 114943 07/30/2008 15:57:16 10,957.00 10,957.00This is just the first of many groups in this view. I just need a simple way to select the row with the max BOOKED_DATES. I've tried everything I could think of but the other two rows are not going away. MAX(BOOKED_DATES) is not working in the HAVING section. I just want my out output to be the rows out of each group with the most recent BOOKED_DATES.
Therefor , my output would be
CUSTOMER_NAME ACCOUNT_NUMBER BOOKED_DATES OUTSTANDING_APPROVALS BOOKED_NOT_BILLED SALES
ABC company, LLC 114943 07/30/2008 15:57:16 10,957.00 10,957.00for ACCOUNT_NUMBER 114943. For the truly curious, the query is below. I'm sure the solution is simple but not to me this day. Maybe it's a Monday thing.
Thanks in Advance.
select distinct
party.party_name CUSTOMER_NAME, --"Customer Name"
cust_acct.account_number ACCOUNT_NUMBER,--"Account Number"
max(h.BOOKED_DATE) BOOKED_DATES,-- "Booked Dates",
osa.OUTSTANDING_SALE_AMT OUTSTANDING_APPROVALS,--"Outstanding Approvals",
ola2.BOOKED_NOT_BILLED BOOKED_NOT_BILLED,
--ola.line_id,
--h.header_id,
sum(nvl(ola.ORDERED_QUANTITY,0) * nvl(ola.UNIT_LIST_PRICE,0)) SALES,
CASE
WHEN
invoiced_amt_info.TERMS = 'Current'
THEN invoiced_amt_info.CURRENT_INV
ELSE NULL
END "CURRENT_IA",--"Current",
CASE
WHEN
invoiced_amt_info.TERMS = 'Current'
THEN invoiced_amt_info.CURRENT_TAX
ELSE NULL
END CURRENT_TAX,--"Current Tax",
CASE
WHEN
invoiced_amt_info.TERMS = '1-30 days'
THEN invoiced_amt_info.CURRENT_INV
ELSE NULL
END LT_30_DAYS,-- "1-30 Days",
CASE
WHEN
invoiced_amt_info.TERMS = '1-30 days'
THEN invoiced_amt_info.CURRENT_TAX
ELSE NULL
END LT_30_DAYS_TAX,-- "1-30 Days Tax",
CASE
WHEN
invoiced_amt_info.TERMS = '31-60 days'
THEN invoiced_amt_info.CURRENT_INV
ELSE NULL
END LT_60_DAYS,-- "1-60 Days",
CASE
WHEN
invoiced_amt_info.TERMS = '31-60 days'
THEN invoiced_amt_info.CURRENT_TAX
ELSE NULL
END LT_60_DAYS_TAX,--"1-60 Days Tax",
CASE
WHEN
invoiced_amt_info.TERMS = '61-90 days'
THEN invoiced_amt_info.CURRENT_INV
ELSE NULL
END LT_90_DAYS,-- "1-90 Days",
CASE
WHEN
invoiced_amt_info.TERMS = '61-90 days'
THEN invoiced_amt_info.CURRENT_TAX
ELSE NULL
END LT_90_DAYS_TAX,-- "1-90 Days Tax",
CASE
WHEN
invoiced_amt_info.TERMS = '90+ days'
THEN invoiced_amt_info.CURRENT_INV
ELSE NULL
END MT_90_PLUS_DAYS,-- "90+ Days",
CASE
WHEN
invoiced_amt_info.TERMS = '90+ days'
THEN invoiced_amt_info.CURRENT_TAX
ELSE NULL
END MT_90_PLUS_DAYS_TAX,--"90+ Days Tax",
uc.UNAPPLIED_CASH UNAPPLIED_CASH--"Unapplied Cash"
FROM
oe_order_headers_all h,
hz_cust_accounts cust_acct,
hz_parties party,
hz_customer_profiles cust_prof,
oe_order_lines_all ola,
select l.HEADER_ID HEADER_ID,
l.sold_to_org_id SOLD_TO_ORG_ID,
sum(nvl(l.ORDERED_QUANTITY,0) * nvl(l.UNIT_LIST_PRICE,0)) BOOKED_NOT_BILLED
from
oe_order_lines_all l
where
l.BOOKED_FLAG <> 'N'
AND l.FLOW_STATUS_CODE <> 'CANCELLED'
AND l.INVOICE_INTERFACE_STATUS_CODE <> 'NO'
group by l.HEADER_ID, l.sold_to_org_id
) ola2,
select INV_AMT.aginglayer, INV_AMT.aging TERMS, sum(INV_AMT.due_amount) CURRENT_INV, INV_AMT.CUSTOMER_ID,--due_amount,--invoiced ammount Currrent
sum(INV_AMT.tax_amount) CURRENT_TAX --tax_amount
from (
select
c.customer_name
, c.customer_number
, c.CUSTOMER_ID
, sum(ps.amount_due_remaining) due_amount
, sum(ps.tax_remaining) tax_amount
, 'Current' aging
, 1 aginglayer
, 1 showord
from ra_customers c
, ar_payment_schedules_all ps
where ps.status = 'OP'
and ps.class <> 'PMT'
and trunc(sysdate - ps.due_date) < 1
and ps.customer_id = c.customer_id
group by c.customer_name
, c.customer_number
, c.CUSTOMER_ID
union
select
c.customer_name
, c.customer_number
, c.CUSTOMER_ID
, sum(ps.amount_due_remaining) due_amount
, sum(ps.tax_remaining) tax_amount
, '1-30 days' aging
, 2 aginglayer
, 2 showord
from ra_customers c
, ar_payment_schedules_all ps
where ps.status = 'OP'
and ps.class <> 'PMT'
and trunc(sysdate - ps.due_date) >= 1
and trunc(sysdate - ps.due_date) <= 30
and ps.customer_id = c.customer_id
group by c.customer_name
, c.customer_number
, c.CUSTOMER_ID
union
select
c.customer_name
, c.customer_number
, c.CUSTOMER_ID
, sum(ps.amount_due_remaining) due_amount
, sum(ps.tax_remaining) tax_amount
, '31-60 days' aging
, 3 aginglayer
, 3 showord
from ra_customers c
, ar_payment_schedules_all ps
where ps.status = 'OP'
and ps.class <> 'PMT'
and trunc(sysdate - ps.due_date) > 30
and trunc(sysdate - ps.due_date) <= 60
and ps.customer_id = c.customer_id
group by c.customer_name
, c.customer_number
, c.CUSTOMER_ID
union
select
c.customer_name
, c.customer_number
, c.CUSTOMER_ID
, sum(ps.amount_due_remaining) due_amount
, sum(ps.tax_remaining) tax_amount
, '61-90 days' aging
, 4 aginglayer
, 4 showord
from ra_customers c
, ar_payment_schedules_all ps
where ps.status = 'OP'
and ps.class <> 'PMT'
and trunc(sysdate - ps.due_date) > 60
and trunc(sysdate - ps.due_date) <= 90
and ps.customer_id = c.customer_id
group by c.customer_name
, c.customer_number
, c.CUSTOMER_ID
union
select
c.customer_name
, c.customer_number
, c.CUSTOMER_ID
, sum(ps.amount_due_remaining) due_amount
, sum(ps.tax_remaining) tax_amount
, '90+ days' aging
, 5 aginglayer
, 5 showord
from ra_customers c
, ar_payment_schedules_all ps
, ra_customer_trx_all trx
, ra_cust_trx_types_all types
where ps.status = 'OP'
and ps.class <> 'PMT'
and trunc(sysdate - ps.due_date) > 90
and ps.customer_id = c.customer_id
and trx.customer_trx_id = ps.customer_trx_id
and types.cust_trx_type_id = trx.cust_trx_type_id
and types.name <> 'CSG-Conversion Pmt'
and types.org_id= 1
group by c.customer_name
, c.customer_number
, c.CUSTOMER_ID
) INV_AMT
group by aginglayer, aging, showord, INV_AMT.CUSTOMER_ID
) invoiced_amt_info,
select ra_cust.customer_name CUSTOMER_NAME, ra_cust.customer_number CUSTOMER_NUMBER, ra_cust.customer_id CUSTOMER_ID,
sum(pay_sched.amount_due_remaining) UNAPPLIED_CASH
from ra_customers ra_cust
, ar_payment_schedules_all pay_sched
where
pay_sched.status = 'OP'
and pay_sched.class = 'PMT'
and pay_sched.due_date > trunc(sysdate - 365)
and pay_sched.customer_id = ra_cust.customer_id
group by ra_cust.customer_name, ra_cust.CUSTOMER_NUMBER, ra_cust.CUSTOMER_ID
) uc,
select qh.cust_account_id CUST_ACCOUNT_ID, sum(qh.total_quote_price) OUTSTANDING_SALE_AMT
from ASO_QUOTE_HEADERS_ALL qh,ASO_QUOTE_STATUSES_TL st
where st.quote_status_id = qh.quote_status_id
and st.meaning ='Credit Hold'
group by qh.cust_account_id
) osa
Where
h.HEADER_ID = ola.HEADER_ID
AND h.HEADER_ID = ola2.HEADER_ID
AND ola.sold_to_org_id = cust_acct.cust_account_id(+)
AND ola2.sold_to_org_id = ola.sold_to_org_id(+)
AND cust_acct.party_id = party.party_id(+)
AND cust_acct.CUST_ACCOUNT_ID = cust_prof.CUST_ACCOUNT_ID(+)
AND cust_prof.party_id = party.party_id
AND cust_prof.CUST_ACCOUNT_ID = invoiced_amt_info.CUSTOMER_ID(+)
AND cust_prof.CUST_ACCOUNT_ID = uc.CUSTOMER_ID(+)
AND cust_prof.CUST_ACCOUNT_ID = osa.CUST_ACCOUNT_ID(+)
group by party.party_name, cust_acct.account_number, invoiced_amt_info.TERMS, osa.OUTSTANDING_SALE_AMT,
ola2.BOOKED_NOT_BILLED,
invoiced_amt_info.CURRENT_INV,
invoiced_amt_info.CURRENT_TAX, uc.UNAPPLIED_CASH
order by party.party_name
Example
--Sample Data
SQL>select deptno, empno, sal,
2 max(sal) over ( partition by deptno order by deptno) mv
3* from emp
SQL> /
DEPTNO EMPNO SAL MV
10 7782 2450 5000
10 7839 5000 5000
10 7934 1300 5000
20 7566 2975 3000
20 7902 3000 3000
20 7876 1100 3000
20 7369 800 3000
20 7788 3000 3000
30 7521 1250 2850
30 7844 1500 2850
30 7499 1600 2850
30 7900 950 2850
30 7698 2850 2850
30 7654 1250 2850
14 rows selected.
SQL>select * from
2 (
3 select deptno, empno, sal,
4 max(sal) over ( partition by deptno order by deptno) mv
5 from emp
6* ) where sal = mv
SQL> /
DEPTNO EMPNO SAL MV
10 7839 5000 5000
20 7902 3000 3000
20 7788 3000 3000
30 7698 2850 2850SS
Similar Messages
-
SSAS Tabular DAX- Need to get MAX value of the MIN (top)hierarchy level row
EDIT:
I got closer to resolving the issue using MAX.
However, If I remove the department hierarchy and just place on the MAX measure I get the single largest value out of all departments.
It would be ideal if the measure could still SUM the "top level" values across everything in the system if the hierarchy is not placed on the rows grouping.
So it returns the largest value for a given department, but if the department hierarchy isn't present I need it to return a SUM of all the level 1 values for all departments...
Basically return MAX value from the MIN L1ID's DeptLevel value, but I can't seem to construct that DAX query. So if DepartmentID hierarchy is on display it gets MAX per row, but if that is removed it dips into MAX GoalValue for each L1ID grouping with
the MIN DeptLevel.
/EDIT
I have a rather odd data table I'm bringing into a SSAS Tabular model.
Instead of having all data at each child level and then it adding up to a grand total in the parent, it has a grand total predefined at each child level.
I just need this tool to display the raw data if at all possible instead of trying to aggregate everything. Filter on active level, ignore child levels.
Is there a way to do that?
Example:
SalesGoalsByDepartmentLevel:
Level1 (top level) = 5,000
Level2( lower level) = 0
Level3(lower still) = 500
Level 4(lowest) = 4,250
So note that adding up all the child levels is still $250 shy of the top 5,000.
IT is just an odd business rule, basically each level is expected to meet that goal or exceed it, the top level goal is 5,000 but management doesn't care where that last 250 comes from, they do are that each defined level is met.
These levels are in a hierarchy so if I view the top level of the hierarchy it adds up to 4250+500+5000=9750 when I just want to see 5,000 at the top level and the details when they drill down.
I added a filter to just filter to the top level, but then when I drill down of course those lower levels are blank.
Is there a way to filter on the current displayed level without aggregating all child levels?
Thanks!You might want to take a look at the Parent-Child Hierarchies pattern here:
http://www.daxpatterns.com/parent-child-hierarchies/
You might write DAX code to check what is the "current" level (see BrowseDepth measure in the sample file you can download) and depending on its level, se the filter to blank to all the levels below, so you don't aggregate "children".
Just an idea, I'm not sure if it corresponds to your requirement and I don't have time to make more tests.
I hope it will be helpful.
Marco Russo (Blog,
Twitter,
LinkedIn) - sqlbi.com:
Articles, Videos,
Tools, Consultancy,
Training
Format with DAX Formatter and design with
DAX Patterns. Learn
Power Pivot and SSAS Tabular. -
How to select a value of a max value of another column in the same row?
pversion pdate pcount
1 11/6/2011 1
0 11/6/2011 25
1 11/6/2011 24
How to select pversion for a maximum pcount, in this case max count is 25 and version will be 0?Like this?
-- Data:
with yourtable as
select 1 pversion , 1 pcount from dual union all
select 0 , 25 from dual union all
select 1 , 24 from dual
-- Query:
select max(pversion ) keep (dense_rank last order by pcount) m_pversion
from yourtable;(When you want to use the query with your real data, you will have to change 'yourtable' to your actual tablename) -
How to pick max value from a column of a table using cursor and iteration
Hello Everybody
I have a table loan_detail
and a column in it loan_amount
now i want to pick values from this table using cursor and then by using iteration i want to pick max value from it using that cursor
here is my table
LOAN_AMOUNT
100
200
300
400
500
5600
700i was able to do it using simple loop concepts but when i was trying to do this by using cursor i was not able to do it .
Regards
PeeyushSQL> SELECT MAX(sal) Highest_Sal,MIN(sal) Lowest_Sal FROM emp;
HIGHEST_SAL LOWEST_SAL
5000 800
SQL> set serverout on
SQL> DECLARE
2 TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
3 sal_tbl tmp_tbl;
4 CURSOR emp_sal IS
5 SELECT sal FROM emp;
6 counter INTEGER := 1;
7 BEGIN
8 FOR i IN emp_sal LOOP
9 sal_tbl(i.sal) := counter;
10 counter := counter + 1;
11 END LOOP;
12 DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
13 DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
14 END;
15 /
Lowest SAL:800
Highest SAL:5000
PL/SQL procedure successfully completed.
SQL> Even smaller
SQL> DECLARE
2 TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
3 sal_tbl tmp_tbl;
4 CURSOR emp_sal IS
5 SELECT sal FROM emp;
6 counter INTEGER := 1;
7 BEGIN
8 FOR i IN emp_sal LOOP
9 sal_tbl(i.sal) := 1;
10 END LOOP;
11 DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
12 DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
13 END;
14 /
Lowest SAL:800
Highest SAL:5000
PL/SQL procedure successfully completed.
SQL> Edited by: Saubhik on Jan 5, 2011 4:41 PM -
Find Index for max value of array
I can use arrayMax to get the max value for a small array, but I need to get which index the max value is located. That will determine which page the user goes to next. Here is my code:
array:
<cfset arrAverages[1]="#qryFairness.fairness#"/>
<cfset arrAverages[2]="#qryHonesty.honesty#"/>
<cfset arrAverages[3]="#qryCompassion.compassion#"/>
<cfset arrAverages[4]="#qrySelfControl.SelfControl#"/>
<cfset arrAverages[5]="#qryMoralConcern.MoralConcern#"/>
These values are gathered from querying values stored in a table.
I can get the max value in the array easily by:
<cfdump var="#arrayMax(arrAverages)#">
What I can't figure out is how to get the row in this array where that max value is located. It seems like it would be so simple, but nothing I have tried has worked.
Thanks,
Richardrking1966 wrote:
I can use arrayMax to get the max value for a small array, but I need to get which index the max value is located. That will determine which page the user goes to next. Here is my code:
array:
<cfset arrAverages[1]="#qryFairness.fairness#"/>
<cfset arrAverages[2]="#qryHonesty.honesty#"/>
<cfset arrAverages[3]="#qryCompassion.compassion#"/>
<cfset arrAverages[4]="#qrySelfControl.SelfControl#"/>
<cfset arrAverages[5]="#qryMoralConcern.MoralConcern#"/>
These values are gathered from querying values stored in a table.
I can get the max value in the array easily by:
<cfdump var="#arrayMax(arrAverages)#">
What I can't figure out is how to get the row in this array where that max value is located. It seems like it would be so simple, but nothing I have tried has worked.
You can find it in one line of code! Here is an example:
<cfset testArr[1]=-183>
<cfset testArr[2]=79>
<cfset testArr[3]=6>
Max.: <cfoutput>#arraymax(testArr)#</cfoutput><br>
Index of max.: <cfoutput>#arrayfindNocase(testArr, arraymax(testArr))#</cfoutput> -
Need to sum max values in a report with Hidden groupings
I have looked all over and have not found my exact situation, so I am posting my first question. I have a report that I have grouped on multiple levels. So my report has a customer/header/detail/release grouping. I have written a custom
expression so that only a single value, which is the max value in the group, is shown in the detail, with all values showing in the release. I have then set my visibility toggle to toggle on header, then detail, then release and I need to sum up those
max values into a field on the report. The custom expression that I have written works correctly when you are showing on the detail level. It gives the correct value, which is the max value in each release.
What I then need the report to do is to sum only that max value and roll that up into the header group, so that I get a total of the max values.
I have tried using the MAX function in my expression to get the correct max value, but I cannot get SSRS 2008 R2 to sum that, and I have tried writing a custom expression that will calculate the max (Non-zero values divided by number of non-zero records) and
both ways work correctly until I try to rollup and sum to the next group level.
I have also tried using a group variable and custom code to get the value and save it to a variable, but I have not had any luck in setting or getting that value correctly back to my report.
At its most basic it feels like I should be able to set a Sum(Max(Fields!ValueColumn.Value) and let SSRS handle how that should be broken out, but after trying that repeatedly I have still had no luck. I cannot adjust the SQL as I need the level of detail
that the report shows, although I could add more fields as long as I don't add any groupings or totals that would reduce the granularity of that data being returned.
Any new avenue to explore would be very helpful.
Thank you in advance,
Chad
Ok, after continuing to search the internet I finally found the extra piece that I was missing that gave me the results I needed. The new expression looks like this:
=runningvalue(Sum(Max(IIF(LEFT(Fields!JobNum.Value,1)="S" AND Fields!Week1STol.Value<>0, CDBL(Fields!Week1STol.Value), 0),"JobItem"),"JobItem"),SUM, "JobItem")
In this I wrapped the original expression of Max in both a Sum and a runningvalue both at the JobItem level to get this rollup value. Now when I open the grouping I get the correct running value at each level.
What this really gives to me is a running total at each of four groupings, even with a "max" value at the detail level. This also allows me to total a max value inline on the report, without needing a hidden row, or report footer.
Thank you to everyone who looked at this, I hope it helps someone else. If this answer is not clear enough, please don't hesitate to add to the comments and I will try to clarify.
Thank you, Chad -
Need help regarding complex calculation using Max value and limiting data after Max date in MDX
I am working on a bit complex calculated measure in SSAS cube script mode.
Scenario /Data Set
Date
A
B
C
A+B
5/29/2014
Null
34
Null
34
6/30/2014
Null
23
45
68
7/15/2014
25
-25
Null
0
8/20/2014
-34
Null
Null
-34
9/30/2014
25
Null
60
25
10/15/2014
45
-45
Null
0
11/20/2014
7
8
Null
15
a) Need to capture latest non-null value of Column C based on date
with above example it should be 60 as of 9/30/2014
b) Need to capture column A+B for all dates.
c) Add values from column (A+B) only after latest date which is after 9/30/2014.
with above example it's last 2 rows and sum is 15
d) Finally add value from step a and step c. which means the calc measure value should be = 75
I need to perform all this logic in MDX. I was able to successfully get step a and b in separate calc measure, however i am not sure how to limit the scope based on certain date criteria. In this case it's, date> Max date(9/30/2014) . Also how should
i add calculated members and regular members?
I was able to get max value of C based on date and max date to limit the scope.
CREATE MEMBER CURRENTCUBE.[Measures].[LatestC] AS
TAIL(
NONEMPTY(
[Date].[Date].CHILDREN*[Measures].[C]),1).ITEM(0) ,visible=1;
CREATE MEMBER CURRENTCUBE.[Measures].[MaxDateofC] AS
TAIL(
NONEMPTY(
[Date].[Date].CHILDREN,[Measures].[C]),1).ITEM(0).MemberValue ,visible=1;
Please help with Scope statement to limit the aggregation of A+B for dates > MaxDateofC? Also further how to add this aggregation value to LatestC calc measure?
Thank YouHi Peddi,
I gave TRUNC to both of the dates. But still the same issue. I think the problem is in returning the BolbDomain.
return blobDomain;
} catch (XDOException xdoe) {
System.out.println("Exception in XDO :");
throw new OAException("Exception in XDO : "+xdoe.getMessage());
catch (SQLException sqle) {
System.out.println("Exception in SQL :");
throw new OAException("SQL Exception : "+sqle.getMessage());
catch (OAException e) {
System.out.println("Exception in OA :");
throw new OAException("Unexpected Error :: " +e.getMessage());
Thanks and Regards,
Myvizhi -
How to get max value of a column in VO?
Hi ,
i need to find the max value of a column named insured value in VO.
Please help!!Hi,
If this value is cuming from the Query then u can easily go for MAX function. If its a user enterable value then u need to iterate through all the rows for that column to find the max of them.
Let me know.
Regards,
Gyan -
How to find out if JTable's selected row is visible?
Hello there,
Given:
a JTable is inserted into a JScrollPane and the number of rows in the table is greater than the vieport size.
A random row within the table gets programmatically selected.
How to find out if the selected row is visible in a JTable visible area?
Your help will be greatly appreciated.
TimThat will make the row visible, but not answer whether it was visible
in the first place. Try something like:
public boolean isRowVisible( JTable table, int row ) {
Rectangle rect = table.getBounds();
int rowHeight = table.getRowHeight();
int viewHeight = table.getParent().getHeight();
int max = rect.y - viewHeight + 1;
int rowPos = - rowHeight * row;
return ( rect.y >= rowPos && rowPos > max );
}assuming all rows have the same height.
: jay -
Query help needed in finding max value between two columns
I have a table as follows:
-- INSERTING into TESTTABLE
Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('A','4.5','AA',0.3,'AB',5.5);
Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('B','1','BB',2.5,'BC',6.9);
Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('C','2.6','CC',3.3,'CD',1.4);
Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('D','1.8','DD',2.9,'DE',1.2);
Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('E','6.8','EE',4.8,'EF',9.6);
Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('F','2.0','FF',6.34,'FG',3.9);
Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('G','1.7','GG',3.6,'GH',5.8);
I want to get results as follows:
COLA COL2 MaxCol MaxColVal
A 4.5 AB 5.5
B 1 BC 6.9
C 2.6 CC 3.3
D 1.8 DD 2.9
E 6.8 EF 9.6
F 2.0 FF 6.34
G 1.7 GH 5.8I want to get the max value of either of the columns COLD or COLF.. Whichever column has got max value, then the corresponding value of COLC and COLE should be returned..
For eg., in first row, COLF has higher value than COLD.. ie., COLF = 5.5 > COLD = 0.3, so for row1, i want the result as MaxCol is AB and MaxColvalue is 5.5..
Similarly for third row, COLD =3.3 > COLF=1.4, so for 3rd row, i want the result as MaxCol is CC and MaxColvalue is 3.3
How is it possible to do this in a qery? Any help.. please..SQL> select cola
2 , col2
3 , case greatest(cold,colf)
4 when cold then colc
5 else cole
6 end maxcol
7 , greatest(cold,colf) maxcolval
8 from testtable
9 /
C COL MA MAXCOLVAL
A 4.5 AB 5,5
B 1 BC 6,9
C 2.6 CC 3,3
D 1.8 DD 2,9
E 6.8 EF 9,6
F 2.0 FF 6,34
G 1.7 GH 5,8
7 rijen zijn geselecteerd.Regards,
Rob. -
How to get the max value of a set of percentage values?
Hi,
I've tried to get the max and min value of a set of calculated percentage values. Such as
Jan Feb March Apr May Jun Min Average Max
0,5 0,8 1,1 0,4 1 0,6 0,4 0,7 1,1
The average value works fine. But with "min" and "max" I have a problem.
I've tried to get the value with the following ways:
- Create a new calc. keyfigure and make a sum of all values: (Jan + Feb + ...) and set the calculation in key figure properties to Min/Max.
- Create a new calc. keyfigure and make a sum of all values and set the aggregation to Min/Max
- Create a selected keyfigure with a filter to the necessary periods and set a calculation to Min (Aggregation is not possible here)
- Create a new cal. keyfigure with all periods and the function Min. e.g. min(Jan, (min Feb, (min (....)
None of this solutions provides the right min and max value. When I use an amount value (e.g. Euro) instead of these percentage values the keyfigure with the min and max function works. The others all provide wrong values.
Is there a solution to get the right min and max value???
It would be a great help when you have any hints.
Thanks
ClaudiaHi Aduri,
thanks for your answer but your solution doesn't work.
The problem is that the periods are defined in a structure with offsets such as
- period-11
- period-10
- period
in this structure elements there is also the keyfigure "netvalue" defined.
In the rows of the report there is another characteristic such as company code.
Is there a solution to find the max and min values of the period values for each company code? Or must I change the data model e.g. copy the keyfigure and make a new keyfigure with another aggregation level?
Thanks for any hints!
Claudia -
Need sum on all coulumns except for one coulumn needs max value
Hi Gurus,
I have a requirement like:
Say I have 3 columns like C1,c2,c3.
On day1 the record values are 100,150,200
On day2 the record values are 100,150,300
End result ..for column C1 and C 2 I should get sum of them
so the result for C1 as per the above values: 200
c2=300
But for C3 column, I should get only maximum value..like 300 (not sum)...
Using case statement by setting a flag on max report date.. we can do this ..Is there any other that this can be achieved. (In ETL or RPD or Front end)
Thanks.For C3 column instead of showing all values like 200, 300 just show max value only so that you can get output as below and when you sum the value remain 300. Try it out. It can be in rpd or in the report.
On day1 the record values are 100,150,300
On day2 the record values are 100,150,300
mark if make sense
Thanks -
How to get the max value in the query??
Plant calday(mm.dd.yyyy) Soldout.Qty
0001 01.01.2005 10
0001 01.02.2005 20
0001 01.03.2005 05
0001 01.04.2005 16
0001 01.05.2005 10
0001 01.06.2005 14
From the above values , how can i findout Max(Soldout.Qty)(i.e 20) for the above week...Suppose present aggregation = summation...How can i findout the value in the Query??don't want to do changes to design...Hi Bhanu,
I tried the calculation results as...Maximum,..
But that will pick the maximum value among the avialable values..like
plant1 max 10
plant2 max 20
plant3 max 30
then it will show as..
plant1 max 30
plant2 max 30
...like this...but my case is
plant1 calday1 10
plant1 calday2 05
plan1 calday7 08
plant2 calday1 10
plant2 calday2 05
plan2 calday7 20
so for each set it need to bring the maximum value... -
I am facing a problem in passing multiple values as out parameters from fo
Hi All,
i am facing a problem in passing multiple values as out parameters from for loop.
EX:
i have a select statment inside a loop like.....
PACKAGE SPEC:
create or replace PACKAGE EMP_PKG AS
TYPE TAB_NUM IS TABLE OF SCOTT.EMP.EMPNO%TYPE;
TYPE TAB_NAME IS TABLE OF SCOTT.EMP.ENAME%TYPE;
TYPE TAB_JOB IS TABLE OF SCOTT.EMP.JOB%TYPE;
temp_table TAB_NUM;
procedure test(temp_TAB_e_no OUT TAB_NUM,
temp_TAB_e_name OUT TAB_NAME,
temp_TAB_e_job OUT TAB_JOB);
END EMP_PKG;
PACKAGE BODY:
create or replace PACKAGE BODY EMP_PKG AS
v_e_no NUMBER;
procedure test(temp_TAB_e_no OUT TAB_NUM,
temp_TAB_e_name OUT TAB_NAME,
temp_TAB_e_job OUT TAB_JOB) IS
BEGIN
select EMPNO bulk collect into temp_table from emp;
for i in 1..temp_table.count loop
v_e_no := temp_table(i);
select empno,
ename,
job
into temp_TAB_e_no(i),
temp_TAB_e_name(i),
temp_TAB_e_job(i)
from emp
where empno = v_e_no;
end loop;
end test;
END EMP_PKG;
PROBLEM FACING IS:
I am expecting all rows returning from bellow select statment ...
select empno,
ename,
job
into temp_TAB_e_no(i),
temp_TAB_e_name(i),
temp_TAB_e_job(i)
from emp
where empno = v_e_no;
But,while running the SP , i am getting error like
ORA-06531: Reference to uninitialized collection
ORA-06512: at "SCOTT.EMP_PKG", line 16
why i am not getting all values as out parameters.please provide a solution for me.
Thanks in advance my friend.user9041629 wrote:
Hi All,
i am facing a problem in passing multiple values as out parameters from for loop.
EX:
i have a select statment inside a loop like.....
PACKAGE SPEC:
create or replace PACKAGE EMP_PKG AS
TYPE TAB_NUM IS TABLE OF SCOTT.EMP.EMPNO%TYPE;
TYPE TAB_NAME IS TABLE OF SCOTT.EMP.ENAME%TYPE;
TYPE TAB_JOB IS TABLE OF SCOTT.EMP.JOB%TYPE;
temp_table TAB_NUM;
procedure test(temp_TAB_e_no OUT TAB_NUM,
temp_TAB_e_name OUT TAB_NAME,
temp_TAB_e_job OUT TAB_JOB);
END EMP_PKG;
PACKAGE BODY:
create or replace PACKAGE BODY EMP_PKG AS
v_e_no NUMBER;
procedure test(temp_TAB_e_no OUT TAB_NUM,
temp_TAB_e_name OUT TAB_NAME,
temp_TAB_e_job OUT TAB_JOB) IS
BEGIN
select EMPNO bulk collect into temp_table from emp;
for i in 1..temp_table.count loop
v_e_no := temp_table(i);
select empno,
ename,
job
into temp_TAB_e_no(i),
temp_TAB_e_name(i),
temp_TAB_e_job(i)
from emp
where empno = v_e_no;
end loop;
end test;
END EMP_PKG;
PROBLEM FACING IS:
I am expecting all rows returning from bellow select statment ...
select empno,
ename,
job
into temp_TAB_e_no(i),
temp_TAB_e_name(i),
temp_TAB_e_job(i)
from emp
where empno = v_e_no;
But,while running the SP , i am getting error like
ORA-06531: Reference to uninitialized collection
ORA-06512: at "SCOTT.EMP_PKG", line 16
why i am not getting all values as out parameters.please provide a solution for me.
Thanks in advance my friend.Probably not a bad thing that this isn't working for you.
This is a horrible way to return the contents of a table.
Are you doing this for educational purpose, or ... what is your goal here? If you just want to return a result set to a client you'd want to look in to using a REF CURSOR and not a bunch of arrays combined with horribly procedural (slow) code. -
Spatial index creation error -ORA-13011: value is out of range
I am trying to create a spatial index and this is what I get.
ERROR at line 1:
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13200: internal error [ROWID:AAAFXYAADAAABxyAAD] in spatial indexing.
ORA-13206: internal error [] while creating the spatial index
ORA-13011: value is out of range
ORA-00600: internal error code, arguments: [kope2upic014], [], [], [], [],
ORA-06512: at "MDSYS.SDO_INDEX_METHOD", line 7
ORA-06512: at line 1
I can't find any documentation as to how to fix this. How do you determine which row of data is out of range? Any help would be greatly appreciated!Hi Jeff,
The data at rowid AAAFXYAADAAABxyAAD has a problem.
Can see what the issue is by doing:
select sdo_geom.validate_geometry(geom_col_name,diminfo)
from your_table_name a, user_sdo_geom_metadata b
where b.table_name='YOUR_TABLE_NAME'
and a.rowid='AAAFXYAADAAABxyAAD';
If you are using Oracle9iR2 then this would be even better:
select sdo_geom.validate_geometry_with_context(geom_col_name,diminfo)
from your_table_name a, user_sdo_geom_metadata b
where b.table_name='YOUR_TABLE_NAME'
and a.rowid='AAAFXYAADAAABxyAAD';
Maybe you are looking for
-
I down loaded sygic on my iPhone 3s but the icon is missing even in the search but when I want to download it again ,it say this application is present, how can I make the icon to show up
-
How to assign a " into a string variable??
say, String s="i am a 'cat'", what if i want to replace the ' with " ?? thanks !
-
Need Suggestion to Stage Process Order related data
Hi All, Could anybody help me by providing the solution or suggestion for the problem which I am describing here. The problem is like to stage the process order related data (which are downloaded from SAP ECC for sending to machine data base or confi
-
Error during activation in adobe form
Hi Guys, While activating the adobe form i am getting the error message as 'Error during activation' with out any futher details.Its not showing any error details.Appreciate you for your help. Regards Syed
-
It appears my firewire portion of my mother board is fried. Can I add a firewire card and bypass so I don't have to replace the board???