Multiple Aggregate function
Hi, I need a help here. Supposedly I want to do a percentage formula based on count(loss_evnt_sr_key)/max(rsum(count(loss_evnt_fact.loss_evnt_sr_key)*100
The scenario given that I need to count for each individual loss_evnt_type_dsc divided by total of loss_evnt_type_dsc
The problem now, when I’ve set the “max(rsum(count(loss_evnt_fact.loss_evnt_sr_key)” column to number, I can do the division but it gives me wrong answer.
Do you have any ways that I can collect the total of loss_evnt_type_dsc ?
I really hope that you can help me in this. Thank you
hi,
i've tried your way, but i give me a wrong total. :(
btw, i have put another thread regarding the issue. you can refer to this forum post: Drill down: Wrong percentage shown
that's actually my real problem. i was thinking to get the total so that it would be easier, but still it gives me wrong number. maybe you can take a look there, and get the real situation of my issue.
Thank you!
Similar Messages
-
How to use multiple aggregate functions in single query
hi to all
The output will be giving first_name,last_name,max(salary),min(salary) and the output will be department wise.From employees table in single query
output will be:
first_name|last_name|max(salary)|min(salary)SELECT first_name||' '||last_name as ename,
MIN(sal) KEEP (DENSE_RANK FIRST ORDER BY sal) OVER (PARTITION BY deptno) "Lowest",
MAX(sal) KEEP (DENSE_RANK LAST ORDER BY sal) OVER (PARTITION BY deptno) "Highest"
FROM emp
ORDER BY deptno, sal;Edited by: Ramio on Jan 10, 2012 10:43 PM -
FetchXML and Aggregate Functions (multiple datasets if necessary)
In fetch xml,
How do I do conduct aggregate functions (most recent, sum, average) on retrieved columns, based on matches with another column.
let's say column a has a value of "Timothy."
How do I then find the total number of column b that also have a value of 'Timothy?'
But then the next value of column a is 'John.'
I would then want to display the total number of column b that have a value of 'John?'
If this is totally impossible, could introducing another dataset help?
Sql is not available here and fetchxml can only do so much. So this is going to have to be done with variables in the actual report.Looks like you're using Dynamics CRM. If that being the case, you may be better off posting in MS Dynamics forums. This forum is specifically for Reporting Services and Power view
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Trying to create a Histogram type/object for aggregate functions
Hi,
I am trying to create an aggregate function that will return a histogram
type.
It doesn't have to be an object that is returned, I don't mind returning
a string but I would like to keep the associative array (or something
else indexed by varchar2) as a static variable between iterations.
I started out with the SecondMax example in
http://www.csis.gvsu.edu/GeneralInfo/Oracle/appdev.920/a96595/dci11agg.htm#1004821
But even seems that even a simpler aggregate function like one strCat
below (which works) has problems because I get multiple permutations for
every combination. The natural way to solve this would be to create an
associative array as a static variable as part of the Histogram (see
code below). However, apparently Oracle refuses to accept associate
arrays in this context (PLS-00355 use of pl/sql table not allowed in
this context).
If there is no easy way to do the histogram quickly can we at least get
something like strCat to work in a specific order with a "partition by
... order by clause"? It seems that even with "PARALLEL_ENABLE"
commented out strCat still calls merge for function calls like:
select hr,qtr, count(tzrwy) rwys,
noam.strCat(cnt) rwycnt,
noam.strCat(tzrwy) config,
sum(cnt) cnt, min(minscore) minscore, max(maxscore) maxscore from
ordrwys group by hr,qtr
Not only does this create duplicate entries in the query result like
"A,B,C" and "A,C,B" it seems that the order in rwycnt and config are not
always the same so a user can not match the results based on their
order.
The difference between my functions and functions like sum and the
secondMax demonstrated in the documentation is that secondMax does not
care about the order in which it gets its arguments and does not need to
maintain an ordered set in order to return the correct results. A good
example of a built in oracle function that does care about all its
arguments and probably has to maintain a similar data structure to the
one I want is the PERCTILE_DISC function. If you can find the code for
that function (or something like it) and forward a reference to me that
in itself would be very helpful.
Thanks,
K.Dingle
CREATE OR REPLACE type Histogram as object
-- TYPE Hist10 IS TABLE OF pls_integer INDEX BY varchar2(10),
-- retval hist10;
-- retval number,
retval noam.const.hist10,
static function ODCIAggregateInitialize (sctx IN OUT Histogram)
return number,
member function ODCIAggregateIterate (self IN OUT Histogram,
value IN varchar2) return number,
member function ODCIAggregateTerminate (self IN Histogram,
returnValue OUT varchar2,
flags IN number) return number,
member function ODCIAggregateMerge (self IN OUT Histogram,
ctx2 IN Histogram) return number
CREATE OR REPLACE type body Histogram is
static function ODCIAggregateInitialize(sctx IN OUT Histogram) return
number is
begin
sctx := const.Hist10();
return ODCIConst.Success;
end;
member function ODCIAggregateIterate(self IN OUT Histogram, value IN
varchar2)
return number is
begin
if self.retval.exist(value)
then self.retval(value):=self.retval(value)+1;
else self.retval(value):=1;
end if;
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self IN Histogram,
returnValue OUT varchar2,
flags IN number)
return number is
begin
returnValue := self.retval;
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self IN OUT Histogram,
ctx2 IN Histogram) return number is
begin
i := ctx2.FIRST; -- get subscript of first element
WHILE i IS NOT NULL LOOP
if self.retval.exist(ctx2(i))
then self.retval(i):=self.retval(i)+ctx2.retval(i);
else self.retval(value):=ctx2.retval(i);
end if;
i := ctx2.NEXT(i); -- get subscript of next element
END LOOP;
return ODCIConst.Success;
end;
end;
CREATE OR REPLACE type stringCat as object
retval varchar2(16383), -- concat of all value to now varchar2, --
highest value seen so far
static function ODCIAggregateInitialize (sctx IN OUT stringCat)
return number,
member function ODCIAggregateIterate (self IN OUT stringCat,
value IN varchar2) return number,
member function ODCIAggregateTerminate (self IN stringCat,
returnValue OUT varchar2,
flags IN number) return number,
member function ODCIAggregateMerge (self IN OUT stringCat,
ctx2 IN stringCat) return number
CREATE OR REPLACE type body stringCat is
static function ODCIAggregateInitialize(sctx IN OUT stringCat) return
number is
begin
sctx := stringCat('');
return ODCIConst.Success;
end;
member function ODCIAggregateIterate(self IN OUT stringCat, value IN
varchar2)
return number is
begin
if self.retval is null
then self.retval:=value;
else self.retval:=self.retval || ',' || value;
end if;
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self IN stringCat,
returnValue OUT varchar2,
flags IN number)
return number is
begin
returnValue := self.retval;
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self IN OUT stringCat,
ctx2 IN stringCat) return number is
begin
self.retval := self.retval || ctx2.retval;
return ODCIConst.Success;
end;
end;
CREATE OR REPLACE FUNCTION StrCat (input varchar2) RETURN varchar2
-- PARALLEL_ENABLE
AGGREGATE USING StringCat;GraphicsConfiguration is an abstract class. You would need to subclass it. From the line of code you posted, it seems like you are going about things the wrong way. What are you trying to accomplish? Shouldn't this question be posted in the Swing or AWT forum?
-
Aggregate Function in SQL subquery
Hello,
I am trying to use the following syntax and it is saying I can't use an aggregate function in a subquery. I can't use a GROUP BY in this case because if another field in the project table (such as status) is different, that project will show up twice.
So in this case I am using this syntax to show the most recent quote within the project.
SELECT PROJECT.*, QUOTE.QuoteDate, QUOTE.QuoteCode
FROM PROJECT LEFT JOIN QUOTE ON PROJECT.ProjectID = QUOTE.ProjectID
WHERE QUOTE.QuoteDate=(SELECT Max(Q.QuoteDate) FROM QUOTE Q WHERE Q.ProjectID = PROJECT.ProjectID);
My goal here is to show the most recent quote within each project (there can be multiple revisions of a quote within each project). I want to show other fields such as the status of the quote, but if the status is different between quotes, the GROUP BY on that
field will cause it to be listed more than once. All I want to show is the most recent quote for each project.
Let me know if this isn't clear.
Thanks.Try the below querySELECT P1.projectID,p1.QuoteDate, Q1.QuoteCode,p1.*
FROM PROJECT P1 inner join (SELECT Q.ProjectID,Max(Q.QuoteDate) QD FROM QUOTE Q group by Q.ProjectID) Q1 on Q1.ProjectID = P1.ProjectID and Q1.QD=P1.QuoteDate-Prashanth -
SSRS - Interactive sorting based on aggregate function
Hi,
I'm trying to add interactive sorting to one of the columns in my tablix.
The soring should be based on the LAST visit date of my child grouping. However interactive sorting is not compatible with aggregate functions apparently.
I'm using the following expression to sort on the period since the last visit:
=DateDiff(
"d"
,LAST(CDate(Fields!Visit_date.Value))
,Today()
Anyone an idea how to get this done?
Regards,
LiskieWhiskyThanks for the input,
Qiuyun Yu: I already applied your method but my issues is that the visit dates are on de level of my
child grouping and per child multiple visit dates are possible. Since I want to complute the days since the last visit I need to take the last visit date and subtract it from today's date.
As you can see there are 2 dates. To compute the days since the last visit I take the last visit date (2015-04-17)
and subtract it from today (2015-04-27). This gives me 10 days. That's ok, no problem there.
But because I'm using the Last() function, I cannot use this expression in the Interactive sorting expression.
LucasF: You are right, but if it's possible to do this in the report I'd prefer that. But ultimately if it's necessary I'll have to do it in MDX then.
Kind regards,
LiskieWhisky -
Analytic function and aggregate function
What are analytic function and aggregate function. What is difference between them?
hi,
Analytic Functions :----------
Analytic functions compute an aggregate value based on a group of rows. They differ from aggregate functions in that they return multiple rows for each group. The group of rows is called a window and is defined by the analytic_clause. For each row, a sliding window of rows is defined. The window determines the range of rows used to perform the calculations for the current row. Window sizes can be based on either a physical number of rows or a logical interval such as time.
Analytic functions are the last set of operations performed in a query except for the final ORDER BY clause. All joins and all WHERE, GROUP BY, and HAVING clauses are completed before the analytic functions are processed. Therefore, analytic functions can appear only in the select list or ORDER BY clause.
Analytic functions are commonly used to compute cumulative, moving, centered, and reporting aggregates.
Aggregate Functions :----------
Aggregate functions return a single result row based on groups of rows, rather than on single rows. Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database divides the rows of a queried table or view into groups. In a query containing a GROUP BY clause, the elements of the select list can be aggregate functions, GROUP BY expressions, constants, or expressions involving one of these. Oracle applies the aggregate functions to each group of rows and returns a single result row for each group.
If you omit the GROUP BY clause, then Oracle applies aggregate functions in the select list to all the rows in the queried table or view. You use aggregate functions in the HAVING clause to eliminate groups from the output based on the results of the aggregate functions, rather than on the values of the individual rows of the queried table or view.
let me know if you are feeling any problem in understanding.
thanks.
Edited by: varun4dba on Jan 27, 2011 3:32 PM -
Aggregate Function for Text Column???
Hi,
Is there a way to group a column's values appearing in multiple rows ( all having some similarity) to be grouped into one single column in one Single Row??
To be more precise,
do we have an Aggregate function which would group values ( may be using commas for separation) for a single column appearing in multiple rows when "grouped By" on some condition.See here:
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
Rgds. -
Error in using aggregate function in Outer Query in Siebel Analytics
Hi,
When I am using aggregate function in outer query in Siebel Analytics I am facing error.
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 59111] The SQL statement must include a GROUP BY clause. (HY000)
Bellow is the code.
SELECT test1.username saw_0, test1.desg saw_1,COUNT (test2.querydate) saw_2
FROM (SELECT POSITION.CBL username,
POSITION.CBP desg
FROM "CM"
WHERE (POSITION.BPTCD = 'Marketing')
AND (POSITION.EDate =TIMESTAMP '1899-01-01 00:00:00'
) test1,
(SELECT users.UN username,
measures."Query Count" querycount,
measures."Max Total Time" secs,
topic.db dashboardname,
"Query Time".DATE querydate
FROM "Plan"
WHERE (topic."Dashboard Name" IN ('DS'))) test2
WHERE test2.username = LOWER (test1.username)
AND test2.dashboardname = 'DS'
GROUP BY test1.username, test1.desgShould your query be a valid SQL query?
I can't think that the query you have would be valid in a SQL plus window.
Chris -
EJB 3.0: EJBQL aggregate functions not working properly
Hi!
We are experiencing problems when using aggregate functions within EJBQL queries. In my case, we have to use max() function to retrieve the max start_date from a specific table. In order to do this, we wrote the following code:
String strQuery = "select max(o.dt_fim) from Questionario o";
Query queryTeste = em.createQuery(strQuery);
List x = queryTeste.getResultList();
OBS: dt_fim is an Oracle 10g datetime column, with its corresponding entity attribute in Questionario entity class.
AFAIK, the query above should return only one record (object instance) containing the date value, right? However, it brougth a list of the entity objects, corresponding to all records in the table, as we had just run "select o from Questionario o".
Examining the server log we can see this behavior:
[TopLink Fine]:2006.09.12 01:47:55.526--
ServerSession(7119662)--Connection(7048401)--Thread(Thread[ApplicationServerThread-0,5,RequestThreadGroup])
--SELECT ID_QUEST, DT_INICIO, DT_FIM, DS_QUEST, DT_CRIACAO, TP_QUEST, NM_QUEST, COD_SEGMENTO, ID_GRUPO FROM TBBOP_QUEST
Are anyone experiencing this issue?
Is there any workaround?
Any help would be much appreciated, since we need to deploy the application for user testing asap.
Thanks in advance.
Best regards,
Gustavo
PS: We are using JDeveloper 10.1.3.0.4(SU4)
Message was edited by:
Gustavo Lopes SobralThe 10.1.3.0 versions of JDeveloper contain our early preview of EJB 3.0 JPA functionality. One limitation is that the query language is not complete (released before the spec was finalized).
You can use TopLink Essentials (JPA Reference implementation) whihc contains a complete compliant implementation of the final specification.
http://otn.oracle.com/jpa
The 10.1.3.1 JDeveloper preview ships with TopLink Essentials.
Doug -
Pivot table in BI Publisher: Different aggregate functions in data columns
Hi, everyone!
I`ve got some troubles with pivot table in my rtf-template.
Here is my xml:
<ROWSET>
<ROW>
<_BI_SUBRF_MO_._MUN_NAME_>МО Петроградский р-н</_BI_SUBRF_MO_._MUN_NAME_>
<_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>714000003</_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>
<_BI_MONTH_DEBET_._BI_DEBET_SUM_>0.0</_BI_MONTH_DEBET_._BI_DEBET_SUM_>
<_BI_CALENDAR_._YEAR__>2009</_BI_CALENDAR_._YEAR__>
<_BI_CALENDAR_._MONTH__>8</_BI_CALENDAR_._MONTH__>
</ROW>
<ROW>
<_BI_SUBRF_MO_._MUN_NAME_>МО Петроградский р-н</_BI_SUBRF_MO_._MUN_NAME_>
<_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>714000004</_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>
<_BI_MONTH_DEBET_._BI_DEBET_SUM_>165.58</_BI_MONTH_DEBET_._BI_DEBET_SUM_>
<_BI_CALENDAR_._YEAR__>2009</_BI_CALENDAR_._YEAR__>
<_BI_CALENDAR_._MONTH__>7</_BI_CALENDAR_._MONTH__>
</ROW>
<ROW>
<_BI_SUBRF_MO_._MUN_NAME_>МО Петроградский р-н</_BI_SUBRF_MO_._MUN_NAME_>
<_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>714000004</_BI_PERS_ACCOUNT_CARD_._BI_PAC_NMB_>
<_BI_MONTH_DEBET_._BI_DEBET_SUM_>165.58</_BI_MONTH_DEBET_._BI_DEBET_SUM_>
<_BI_CALENDAR_._YEAR__>2009</_BI_CALENDAR_._YEAR__>
<_BI_CALENDAR_._MONTH__>7</_BI_CALENDAR_._MONTH__>
</ROW>
...... and so on..
</ROWSET>
In the pivot table i`d like to see one row for every BISUBRF_MO_._MUN_NAME_ using BICALENDAR_._YEAR__ and BICALENDAR_._MONTH__ as measures and sum of BIMONTH_DEBET_._BI_DEBET_SUM_ and count of unique (or at least just count of) BIPERS_ACCOUNT_CARD_._BI_PAC_NMB_ in cells.
I create a pivot table using wizard, everything ok except one thing: as i understand, in pivot table for data in rows we can use only one kind of aggregate function e.g. only sum or only count.
Is there any way to use different aggregate functions in data cells?
Thank youAs you can see, when we use crosstab tag we can specify only one aggregate function for data cells.
Is there any way to get in XSL-FO (where we can what really happens) instead of:
<T1>
<xsl:value-of select="sum(current-group()/_BI_PERS_ACCOUNT_CARD_._BI_PAC_UNID_)"/>
</T1>
<T2>
<xsl:value-of select="sum(current-group()/_BI_MONTH_DEBET_._BI_DEBET_SUM_)"/>
</T2>
this
<T1>
<xsl:value-of select="sum(current-group()/_BI_PERS_ACCOUNT_CARD_._BI_PAC_UNID_)"/>
</T1>
<T2>
<xsl:value-of select="count(current-group()/_BI_MONTH_DEBET_._BI_DEBET_SUM_)"/>
</T2>
Edited by: user12115038 on 26.10.2009 8:08 -
Not able to use multiple grid function in smartview
Hi,
One of my client want to use multiple grid function in Hyperion smartview and he was using latest version of Hyperion smartview 11.1.2.5. But still that feature was not enabled in smart view.
Our's is windows environment and essbase server version 11.1.2.1 and APS version 11.1.2.1.
Can anyone please help me to resolve this issue.
Please let me know if i might missed anything or still if any info required.
Thanks in Advance.
Thanks,
Kumar.Thanks for your help Celvin. I will try to apply the path for both APS and essbase server and will check.
Thanks once again.
Regards,
Vinay Kumar. -
Multiple Partner Functions for a Sales document Item
Hi,
Can you please advise on modeling scenario for showing multiple partner functions for a given sales document in BI Report ..
Because Key figure values should not be distributed for multiple records just becos of multiple partner functions but users want to see them in the reports along with sales doc and key figure
I am explaining bit more clearly...
I can achieve above requirement by having below model ..
SDOC ITEM PF1 PF2 PF3 AMOUNT
1000 10 AB CD EF 50000
PF : Partner Function
but as I feel it is a complicated task to add more and more columns fro partner functions as and when new partner functions have been added or requested to show by users at sales doc level...
So Can you please advise a better solution to meet the same requirement.
Thanks & Regards,
BRK
Please advise me on this scenario
Thanks & Regards,
BRK
Edited by: BRK on Jul 22, 2008 9:19 AM
Edited by: BRK on Jul 22, 2008 9:29 AMSalesDoc______Item_______PartnerFunction________Amount
80000_________10_____________A1_______________$1000
80000_________10_____________A2_______________$1000
80000_________10_____________A3_______________$1000
This will be the normal display in the cube if there is only one Partner Function.
But what we need is
SalesDoc______Item_______PartnerFunction________Amount
80000_________10_____________A1_______________$1000
80000_________10_____________A2_________________' '
80000_________10_____________A3_________________' '
The Amount (KF) should be populated only for the first record for a SalesDoc / Item combo.
You load data from source to the ODS, say delta.
Suppose that the below record is already available in the ODS.
SalesDoc______Item_______PartnerFunction________Amount
80000_________10_____________A1_______________$1000
And you get the following data as DELTA in the Data_Package from the source.
SalesDoc______Item_______PartnerFunction________Amount
80000_________10_____________A2_______________$1000
80000_________10_____________A3_______________$1000
If you populate the Amount again for these 2 records, then the total would sum to $3000, which is wrong.
So what we do is,
Write a Select stmt for ALL ENTRIES in Data_Package and fetch the records from the target ODS. Have it in an Internal table, say t_ODS1
Take the SalesDoc / Item from the Data_Package and chk if it is present in the internal table t_ODS1.
If it is present, then populate the Amount as ' ' (Blank)
Else populate the Amount as $1000.
Say, you are getting 3 new records, which is not present in the ODS1.
In that case, your internal table t_ODS1 will be blank.
Now again, we need to populate the Amount only for the first record among the 3 records.
So, here comes the "Flag".
Set the Flag as X, when we populate the Amount.
Everytime chk the Flag <> X.
Only if it is <> X, populate the Amount.
Else Leave it Balnk.
Hope I have explained in detail
Regards,
Balaji V -
Issue in pivot while using aggregate functions
when I use this below query in oracle sql developer
------------->select sum(round(8.08/0.54,2)*30) from dual.
i am getting result as 448.8.it is a correct value
but i use this below queries in pivot as same like above query i am getting result of doubled value 914.4.
PIVOT
SUM(round(ROUND(sellout,2)/6,2)) AS LAST_6_MON_SELL_OUT,
SUM(ROUND(inventory,2)) AS INVENTORY_INTINS_1,
Sum(round(ROUND(inventory,2)/round(ROUND(sellout,2)/6,2),2)*30) As Stockperday
FOR PRODUCT IN (56,78)
actually i am getting value for SUM(round(ROUND(sellout,2)/6,2)) is 0.54,*SUM(ROUND(inventory,2))* is 8.08 i the above query ,but i am getting wrong value for this aggregate function Sum(round(ROUND(inventory,2)/round(ROUND(sellout,2)/6,2),2)30)* as 914.4.but actual value is 448.8
why this problem.can anybody explain me.why this problemTry ur luck in 'sql plsql thread'
PL/SQL -
Why doesn't PIVOT clause work with COLLECT aggregate function in 11g ?
Hello all !
I am really puzzled as to what is considered an aggregate function in the context of the PIVOT clause in 11g.
I have been toying with quite a few things related to collections lately and this arose as an aside :
CREATE TABLE TEST_COLL
NODE_ID VARCHAR2(15 CHAR) NOT NULL,
NODE_VALUE VARCHAR2(45 CHAR) NOT NULL,
NODE_LEVEL NUMBER(1) NOT NULL
CREATE OR REPLACE TYPE TREE_NODE AS OBJECT
NODE_KEY VARCHAR2( 15 CHAR),
NODE_NAME VARCHAR2(127 CHAR)
CREATE OR REPLACE TYPE TREE_NODES AS TABLE OF TREE_NODE NOT NULL;At this stage I am sure we all agree that the query
SELECT NODE_LEVEL,
CAST(COLLECT(TREE_NODE(NODE_ID, NODE_VALUE)) AS TREE_NODES) AS NODES
FROM TEST_COLL
GROUP BY NODE_LEVEL;is perfectly valid as the COLLECT function is an aggregate function according to the [Official Documentation|http://docs.oracle.com/cd/E11882_01/server.112/e10592/functions031.htm#i1271564]
But then, one of the following two queries should work
SELECT CAST(REGION_NODES AS TREE_NODES) AS REGIONS,
CAST(DEPARTMENT_NODES AS TREE_NODES) AS DEPARTMENTS,
CAST(AREA_NODES AS TREE_NODES) AS AREAS,
CAST(CENTRE_NODES AS TREE_NODES) AS CENTRES
FROM (SELECT NODE_LEVEL, TREE_NODE(NODE_ID, NODE_VALUE) AS NODE
FROM TREE_COLL
PIVOT (COLLECT(NODE) FOR NODE_LEVEL IN (1 AS REGION_NODES,
2 AS DEPARTMENT_NODES,
3 AS AREA_NODES,
4 AS CENTRE_NODES
or (better)
SELECT REGION_NODES AS REGIONS,
DEPARTMENT_NODES AS DEPARTMENTS,
AREA_NODES AS AREAS,
CENTRE_NODES AS CENTRES
FROM (SELECT NODE_LEVEL, TREE_NODE(NODE_ID, NODE_VALUE) AS NODE
FROM TREE_COLL
PIVOT (CAST(COLLECT(NODE) AS TREE_NODES) FOR NODE_LEVEL IN (1 AS REGION_NODES,
2 AS DEPARTMENT_NODES,
3 AS AREA_NODES,
4 AS CENTRE_NODES
);yet, both fail with
ORA-56902: expect aggregate function inside pivot operationInvestigating further, I found the same behaviour when using XMLAGG as the aggregate function in the PIVOT clause.
Is this normal ? And if it is, is there any other way to achieve the result I was anticipating ?
My version is
SQL> SELECT BANNER FROM V$VERSION;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - ProductionThanks in advance
Best Regards
PhilipMost likely a bug. But you can bypass it by using any other aggregate making sure group consists of a single row and apply collect to a pivoted value. Yes, the cost is double aggregation. And also there is another cost - you would need to create MAP member function otherwise aggreations like MAX/MIN, etc. will not work:
CREATE OR REPLACE TYPE TREE_NODE AS OBJECT
NODE_KEY VARCHAR2( 15 CHAR),
NODE_NAME VARCHAR2(127 CHAR),
map member function f return varchar2
Type created.
CREATE OR REPLACE TYPE BODY TREE_NODE AS
map member function f return varchar2 is
begin
return NODE_NAME;
end f;
end;
Type body created.
CREATE OR REPLACE TYPE TREE_NODES AS TABLE OF TREE_NODE NOT NULL
Type created.
SQL> select *
2 from test_coll
3 /
NODE_ID NODE_VALUE NODE_LEVEL
1 A 1
2 B 2
3 C 3
4 D 4
5 E 1
6 F 2
7 G 3
8 H 4
8 rows selected.
SQL> Now:
SELECT CAST(COLLECT(REGION_NODES) AS TREE_NODES) AS REGIONS,
CAST(COLLECT(DEPARTMENT_NODES) AS TREE_NODES) AS DEPARTMENTS,
CAST(COLLECT(AREA_NODES) AS TREE_NODES) AS AREAS,
CAST(COLLECT(CENTRE_NODES) AS TREE_NODES) AS CENTRES
FROM (
SELECT ROWID RID,
NODE_LEVEL,
TREE_NODE(NODE_ID, NODE_VALUE) AS NODE
FROM TEST_COLL
PIVOT (MAX(NODE) FOR NODE_LEVEL IN (
1 AS REGION_NODES,
2 AS DEPARTMENT_NODES,
3 AS AREA_NODES,
4 AS CENTRE_NODES
REGIONS(NODE_KEY, NODE_NAME) DEPARTMENTS(NODE_KEY, NODE_NAME) AREAS(NODE_KEY, NODE_NAME) CENTRES(NODE_KEY, NODE_NAME)
TREE_NODES(TREE_NODE('1', 'A'), TREE_NODE('5', 'E')) TREE_NODES(TREE_NODE('6', 'F'), TREE_NODE('2', 'B')) TREE_NODES(TREE_NODE('7', 'G'), TREE_NODE('3', 'C')) TREE_NODES(TREE_NODE('8', 'H'), TREE_NODE('4', 'D'))
SQL> SY.
Maybe you are looking for
-
Can't see photos after update to 9.3.2
I'm using Lion 10.7.4 and recently updated to iPhoto 9.3.2. Though I can see my photos in thumbnails they will not show up in the iPhoto window when double clicked. Each event is (blank) black though it retains its title. I've tried command-option w
-
When using two log ins how do I migrate one to a new macbook pro
I have a macbook pro that is 3 years old and have recently purchased the new retina macbook pro. My husband will continue to use the older model and he has his files, contacts and music when he logs in but I also have mine when I log on the same mac
-
I can't open most files from DNG Converter 5.5b (Olympus E-P1)
I have a bunch of E-P1 photos taken in RAW (.ORF files) and was waiting eagerly for support by ACR. I tried the DNG Converter 5.5b today and converted all my images to DNG. When I tried to import the DNGs in iPhoto, it imported only 32 files out of 8
-
Payment block for vendor based on value.
Hi Friends, Is there any way to set like, If the payment is >$5000 for vendor 100100, Invoice must be blocked for payment automatically. If the payment is <$5000, Invoice should not block for payment. Best regards, RAMAN.
-
I am setting up my mac mini lion server. I have a public IP address that points to my server but I need the mac server to redirect it to a different port on my server. I want to be able to type in the address in the web browser and go to the design