analytical function and the aggregate function
What are the analytical function and the aggregate function. What is the difference between them?Hello
Analytic Functions : -.
Analytical functions calculate a value of aggregation based on a group of lines. They differ from aggregate functions because they return several rows for each group. The Group of rows is called a window and is defined by the analytic_clause. For each line, a sliding window of lines is defined. The window determines the range of lines used for the calculations for the current line. Window sizes can be based on a physical number of rows or a logic as the time interval.
Analytical functions are the last set of operations performed in a query with the exception of the last ORDER BY clause. Every joint and every WHERE, GROUP BY and HAVING clauses are met before the analytical functions are handled. As a result, analytic functions can only appear in the select list or the ORDER BY clause.
Analytical functions are commonly used to calculate cumulative aggregates, moving, centered and considered.
Aggregate functions : -.
Aggregate functions return a line of single result based on the groups of lines, rather than on the unique lines. Aggregate functions can appear in selection lists, as well as in the HAVING and ORDER BY clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database splits the rows in a table when asked or seen in groups. In a query that contains a GROUP BY clause, the select list items can be aggregation functions, GROUP BY constant expressions or expressions involving one of them. Oracle applies the functions of aggregation for each group of rows and returns a single result for each group line.
If you omit the GROUP BY clause, Oracle then applies any aggregate functions in the select list for all rows in the table queried or the view. You use aggregate functions in the HAVING clause to eliminate groups of the output based on the results of aggregate functions, rather than the values of the individual lines of the queried table or view.
Let me know if you feel any problem understanding.
Thank you.
Published by: varun4dba on January 27, 2011 15:32
Tags: Database
Similar Questions
-
String and the aggregate function
Hi all
Suppose that in the HR schema example, I want to count all the employee table names that start by the of the. The following queries employees with this name:
How to query number of employees who have first names beginning by the of '?SQL> select first_name,job_id,count(first_name) from employees where first_name like 'S%' group by first_name, job_id; FIRST_NAME JOB_ID COUNT(FIRST_NAME) -------------------- ---------- ----------------- Sundita SA_REP 1 Samuel SH_CLERK 1 Shelli PU_CLERK 1 Sigal PU_CLERK 1 Shelley AC_MGR 1 Steven AD_PRES 1 Susan HR_REP 1 Sarath SA_REP 1 Shanta ST_MAN 1 Steven ST_CLERK 1 Stephen ST_CLERK 1 FIRST_NAME JOB_ID COUNT(FIRST_NAME) -------------------- ---------- ----------------- Sundar SA_REP 1 Sarah SH_CLERK 1 13 rows selected.
Best regards
ValerieAlso I want to query first name and number of count, is this possible?
I think you want:
SELECT FIRST_NAME, COUNT (*)
EMPLOYEES
WHERE NAME LIKE %'
ROLLUP GROUP ((FIRST_NAME)) -
Query SQL using Group by and the aggregate function
Hi all
I need your help in writing a SQL query to achieve the following objectives.
Scenario:
I have a table with 3 columns. There are 3 possible values for col3 - success, failure, and error.
Now I need a query that can give me the summary figures for distinct values for col3 for each GROUP BY col1 and col2 values. When there is no values for col3, then it should return ZERO count.
The example data:
Col1 Col2 Col3
success of ABC 01
success of ABC 02
success of ABC 01
ABC 01 failure
ABC 01 error
ABC 02 failure
ABC 03 error
XYZ 07 failure
Power required:
C1 c2 s_cnt F_cnt E_cnt (title)
ABC 01 2 1 1
ABC 02 1 1 0
03 0 0 1 ABC
XYZ 07 0 1 0
s_cnt = number of success; F_cnt = number of failure; E_cnt = number of errors
Please note that the exit should have 5 columns col1, col2, group of (col1, col2) count (success), group of (col1, col2) count (failure), group of (col1, col2) count (error)
and wherever there are n ROWS, then it should return ZERO.
Thanks in advance.
Kind regards
ShivaHi, Shiva,
Welcome to the forum!
Here's one way:
SELECT col1 , col2 , COUNT ( CASE WHEN col3 = 'success' THEN 1 END ) AS s_cnt , COUNT ( CASE WHEN col3 = 'failure' THEN 1 END ) AS f_cnt , COUNT ( CASE WHEN col3 = 'Error' THEN 1 END ) AS e_cnt FROM table_x GROUP BY col1 , col2 ;
Whenever you have a problem, post a small example data (CREATE TABLE and only relevant columns, INSERT statements). If you do not, then don't expect answers, you can get to test.
Also post the results desired from these data. -
Oracle 11g Release 2
I'm assuming that the best solution is the use of analytical functions.
create table test3 ( part_type_id varchar2(50) ,group_id number ,part_desc_id number ,part_cmt varchar2(50) ) / insert into test3 values( 'ABC123',1,10,'comment1'); insert into test3 values( 'ABC123',1,10,'comment2'); insert into test3 values( 'ABC123',2,15,'comment1'); insert into test3 values( 'ABC123',2,15,'comment2'); insert into test3 values( 'EFG123',25,75,'comment3'); insert into test3 values( 'EFG123',25,75,'comment4'); insert into test3 values( 'EFG123',25,75,'comment5'); insert into test3 values( 'XYZ123',1,10,'comment6'); insert into test3 values( 'XYZ123',2,15,'comment7'); commit; select * from test3; PART_TYPE_ID GROUP_ID PART_DESC_ID PART_CMT -------------------- ---------- ------------ -------------------- ABC123 1 10 comment1 ABC123 1 10 comment2 ABC123 2 15 comment1 ABC123 2 15 comment2 EDG123 25 75 comment3 EDG123 25 75 comment4 EDG123 25 75 comment5 XYZ123 1 10 comment6 XYZ123 2 15 comment7 9 rows selected. Desired output: PART_TYPE_ID GROUP_ID PART_DESC_ID PART_CMT -------------------- ---------- ------------ -------------------- ABC123 1 10 comment1 ABC123 2 15 comment1 XYZ123 1 10 comment1 XYZ123 2 15 comment2 RULE: where one part_type_id has multiple (2 or more distinct combinations) of group_id/part_desc_id NOTE: There are about 12 columns in the table, for brevity I only included 4.
Post edited by: orclrunner was updated desired output and rule
Hello
Here's one way:
WITH got_d_count AS
(
SELECT part_type_id, group_id, part_desc_id
MIN (part_cmt) AS min_part_cmt
COUNT AS d_count (*) OVER (PARTITION BY part_type_id)
OF test3
GROUP BY part_type_id, group_id, part_desc_id
)
SELECT DISTINCT
group_id, part_desc_id, part_type_id, min_part_cmt
OF got_d_count
WHERE d_count > 1
;
Output:
GROUP_ID PART_DESC_ID MIN_PART_CMT PART_TYPE_ID
------------ ---------- ------------ ------------
ABC123 1 10 comment1
ABC123 2 15 comment1
XYZ123 1 10 comment6
XYZ123 2 15 comment7
Analytical functions, such as the COUNTY and MIN, many global versions, in addition, it can give the same results. Use the analytical versions when each row of output corresponds to exactly 1 row of input and the aggregate and GROUP BY version when each line of output corresponds to a group of lines 1 or more input. In this issue, each line of output appears to be a group of input lines having the same group_id, part_type_id, and part_desc_id (I'm guessing just, this only has never stated), so I used GROUP BY to get 1 row of output for every input lines.
-
Page BI Analytics and the Publisher is unable to connect
Hi friends,
I did OBIEE 11.1.1.7 the installation of windows server 2008 R2 Enterprise successfully, I can connect to the console, EM, analytic and BI publisher with the weblogic user.
After that, I installed BIAPPS 7.9.6.4 with OBIEE upward and this OBIA also installed successfully. But after installation of OBIA if I tried to connect to the analytical page and BI publisher with the weblogic user, it is unable to connect and that is to say as im getting error while logging into the analytical page below
Unable to sign in an invalid user name or password has been entered in the analytical page.
If I tried to open BI publisher link im getting the error as
Server not initialized. Please ensure that the repository is ready.
Since then, I have all services in operational Bi, but I couldn't connect to the analytical page and the editor.
But I can connect to the console with the weblogic user and page EM.
Im not sure the problem behind all this, kindly help me with this friends.
Thanks in advance.
Kind regards
Saro
Hi guys,.
The problem is solved and explained in the Note 1561846.1 MOS technique with a fix.
Thank you
Kind regards
Saro
-
Bug with the aggregate function and no group
When I run the following query:
I get this result:with the_table as ( select 1 as id, 100 as cost from dual union all select 2 as id, 200 as cost from dual union all select 3 as id, 300 as cost from dual union all select 4 as id, 400 as cost from dual union all select 5 as id, 500 as cost from dual ) select id, cost from ( select id, cost from the_table -- union all -- select 0 as id, sum(cost) as cost from the_table where 0 = 1 -- group by 1 ) order by id;
However, when I "uncomment" the line "Group 1", the query works as expected (without the id = rank 0).ID COST -- ------ 0 <null> 1 100 2 200 3 300 4 400 5 500
This occurs even when "the_table" is an array.
Someone else comes through this (and if so, how long is a problem)?
The database is 11.2.0.2.0 64-bit.
EDIT: It also happens without a Union - the following returns a single line (with null 0 and cost of id) without the Group By and no line with her:
Edited by: Donbot February 15, 2012 10:29select id, cost from ( select 0 as id, sum(cost) as cost from ( select 1 as id, 100 as cost from dual union all select 2 as id, 200 as cost from dual union all select 3 as id, 300 as cost from dual union all select 4 as id, 400 as cost from dual union all select 5 as id, 500 as cost from dual ) where 0 = 1 -- group by 1 ) order by id
Donbot wrote:
Someone else comes through this (and if so, how long is a problem)?The database is 11.2.0.2.0 64-bit.
This is a documented behavior.
http://docs.Oracle.com/CD/E11882_01/server.112/e26088/functions003.htm#SQLRF20035
"
All except COUNT (*) GROUPING and GROUPING_ID aggregate functions ignore NULL values. You can use the NVL function in the argument of an aggregation function to substitute a value for a null value. COUNTY and REGR_COUNT never return null, but return a number or zero. For all remaining functions of aggregation, * if the DataSet contains no line, * or if it contains only the rows with NULL values as arguments to the aggregate function, * then the function returns null.*
" -
The appropriate to a MAX on an analytical function syntax
I am trying to apply a MAX function on a function analytically than doing a MAX as well. However, I can't understand the appropriate syntax. That's what I tried:
When I try to run the above query, I get a 't.col1 is invalid in the select list because it is not contained in an aggregate function or the GROUP BY clause error.SELECT MAX(MAX(t.col1) OVER (PARTITION BY t.col2) AS max_col FROM sample_table t;
You must encapsulate the query that has the analytical function in another query and then make the max in the outer query.
-
by using the analytical function to get the right output.
Hello all;
I have the following date of sample below
It's the output I wantcreate table temp_one ( id number(30), placeid varchar2(400), issuedate date, person varchar2(400), failures number(30), primary key(id) ); insert into temp_one values (1, 'NY', to_date('03/04/2011', 'MM/DD/YYYY'), 'John', 3); insert into temp_one values (2, 'NY', to_date('03/03/2011', 'MM/DD/YYYY'), 'Adam', 7); insert into temp_one values (3, 'Mexico', to_date('03/04/2011', 'MM/DD/YYYY'), 'Wendy', 3); insert into temp_one values (4, 'Mexico', to_date('03/14/2011', 'MM/DD/YYYY'), 'Gerry', 3); insert into temp_one values (5, 'Mexico', to_date('03/15/2011', 'MM/DD/YYYY'), 'Zick', 9); insert into temp_one values (6, 'London', to_date('03/16/2011', 'MM/DD/YYYY'), 'Mike', 8);
Any help is appreciated. I'll post my request as soon as I can think of a good logic for this...placeid issueperiod failures NY 02/28/2011 - 03/06/2011 10 Mexico 02/28/2011 - 03/06/2011 3 Mexico 03/14/2011 - 03/20/2011 12 London 03/14/2011 - 03/20/2011 8
Hello
user13328581 wrote:
... Please note, I'm still learning how to use analytical functions.It doesn't matter; analytical functions will not help in this problem. The SUM aggregate function is all you need.
But what do you need to GROUP BY? What is the value of each row of the result will represent? A placeid? Yes, each line will represent only placedid, but it will be divided further. You want a separate line of the output for each placeid and every week, then you'll want of the week and GROUP BY placeid. You don't want to GROUP BY the raw issuedate; that would put on 3 March and 4 March in separate groups. And you don't want to GROUP BY failures; This would mean that a line with 3 failures could never be in the same group in line with 9 failures.This becomes the output you posted from the sample data you posted:
SELECT placeid , TO_CHAR ( TRUNC (issuedate, 'IW') , 'MM/DD/YYYY' ) || ' - '|| TO_CHAR ( TRUNC (issuedate, 'IW') + 6 , 'MM/DD/YYY' ) AS issueperiod , SUM (failures) AS sumfailures FROM temp_one GROUP BY placeid , TRUNC (issuedate, 'IW') ;
You can use a subquery to calculate TRUNC (issuedate, 'IW') once. The code would be of about as complicated, efficiency probably will not improve substantially and the results would be the same.
-
With the help of analytical functions
Hi all
I'm using ODI 11 g (11.1.1.3.0) and I'm doing an interface using analytical functions in the column map, something like below.
Salary on (partition of...)
The problem is that when ODI saw the sum he considers this an aggregate function and the group. Is it possible to understand that it is not an aggregate in ODI function?
I tried to create an option to specify whether it is analytic, then updated IKM with no luck.
< % if (odiRef.getUserExit("ANALYTIC").equals("1")) {% >}
< %} else {% >}
< % = odiRef.getGrpBy (i) % >
< % = odiRef.getHaving (i) % >
< %} % >
Thanks in advanceSeth,
Try this thing posted by Uli:
http://www.business-intelligence-quotient.com/?p=905 -
How to use Group by in the analytic function
I need to write the Department that has the minimum wage in a row. She must be with analytical function, but I have problem in group by. I can't use min() without group by.
Select * from (min (sal) select min_salary, deptno, RANK() ON RN (ORDER BY sal CSA, CSA rownum) of the Group of emp by deptno) < 20 WHERE RN order by deptno;
Published by: senza on 6.11.2009 16:09Hello
senza wrote:
I need to write the Department that has the minimum wage in a row. She must be with analytic functionTherefore with an analytic function? Looks like it is a duty.
The best way to get these results is with an aggregate, not analysis, function:
SELECT MIN (deptno) KEEP (DENSE_RANK FIRST ORDER BY sal) AS dept_with_lowest_sal FROM scott.emp ;
Note that you do not need a subquery.
This can be modififed if, for example, you want the lowest Department with the sal for each job.But if your mission is to use an analytical function, that's what you have to do.
but I have problem in group by. I can't use min() without group by.
Of course, you can use MIN without GROUP BY. Almost all of the aggregate (including MIN) functions have analytical equivalents.
However, in this issue, you don't need to. The best analytical approach RANK only, not use MIN. If you ORDER BY sal, the lines with rank = 1 will have the minimum wage.Select * from (min (sal) select min_salary, deptno, RANK() ON RN (ORDER BY sal CSA, CSA rownum) of the Group of emp by deptno) WHERE the RN< 20="" order="" by="">
Try to select plain old sal instead of MIN (sal) and get reid of the GROUP BY clause.
Add ROWNUM in the ORDER BY clause is to make RANK return the same result as ROW_NUMBER, every time that it is a tie for the sal, the output will still be distinct numbers. which line gets the lower number will be quite arbitrary, and not necessarily the same every time you run the query. For example, MARTIN and WARD have exactly the same salary, 1250. The query you posted would assign rn = 4 to one of them and rn = 5 to another. Who gets 4? It's a toss-up. It could be MARTIN the first time you try, and WARD the next. (In fact, in a very small table like scott.emp, it probably will be consistent, but always arbitrary.) If this is what you want, it would be clearer and simpler just to use ROW_NUMEBR instead of RANK.
-
Consolidation of the unauthorized analytical functions
Hi all, I have a calculated field named Calculation1 with the following calculation:
AVG (Resolution_time) KEEP (DENSE_RANK FIRST ORDER BY RANK) OVER (PARTITION BY "The COMPLETE user groups". Name of the group, "notes report COMPLETE #7. Name of the resource)
The result of this calculation is correct, but is repeated for all the rows in the dataset.
Group Name Resourse name Calculation1
I tried to create another calculation to have only one value for the couple "(nom dele de groupe, le nom de la ressource) like AVG (Calculation1) but I got the error: unauthorized consolidation of analytical functions"
SH Group Mr. A 10
SH Group Mr. A 10
SH Group Mr. A 10
SH Group Mr. A 10
SH Group Mr. A 10
...............................................
5112 rows
I have also seen inside the spreadsheet "Edit" Panel that the Calculation1 * is not represented * with the "Sigma" symbol I (like for instance a simple (field_1) AVG) and inside the SQL, I did not GROUP BY group name, name of the resource...
I would like to see ONLY a line like:
Group Name Resourse name Calculation1
.. .that means I've grouped by group name, name of the resource
SH Group Mr. A 10
Anyone know how I can get this result or any workaround?
Thanks in advance
AlexHello
You can do this completely in the workbook because you need to aggregate several times. You need computing rank as a calculated using Disco admin folder item.
Then you should be able to use
AVG (CASE WHEN STATUS = 1 THEN Resolution_time END)
in the workbook.
Rod West
-
A job for the analytical function "PARTION OF?
Hello
I'm still a little fuzzy on the use of partitions, but this looks like a possible candidate for me.
I need to count the number of different customers who visit an office in one day. If a customer visits an office more than once in a single day that counts for 1.
Entry
OFFICE CLIENT TRAN_DATE
1-11-1 April 09
1-11-1 April 09
1-11-1 April 09
1 11 2 April 09
2 22 2 April 09
2 22 2 April 09
2 33 2 April 09
Select a.office as 'OFFICE', a.customer AS 'CUSTOMER', a.tran_date AS 'TRAN_DATE', COUNT (*)
Of
(SELECT 1 AS 'OFFICE', AS A 'CUSTOMER' 11, APRIL 1, 2009 "AS"TRAN_DATE"OF THE DOUBLE
UNION ALL
SELECT 1, 11, APRIL 1, 2009 "OF THE DOUBLE
UNION ALL
SELECT 1, 11, APRIL 1, 2009 "OF THE DOUBLE
UNION ALL
SELECT 1: 11, 2 APRIL 2009 "OF THE DOUBLE
UNION ALL
SELECT 2: 22, APRIL 2, 2009 "OF THE DOUBLE
UNION ALL
SELECT 2: 22, APRIL 2, 2009 "OF THE DOUBLE
UNION ALL
SELECT 2: 33, APRIL 2, 2009 "OF THE DOUBLE
) one;
Desired result
1 1 April 09 1
1-2 April 09 1
2 2 April 09 2
Is this possible with partitions, do I have to use subqueries, or some other methid?
Thanks in advance for your help,
Lou
Published by: wind in the face on April 15, 2009 13:34Hey, Lou,
PARTITION BY is not a function.
COUNT is a function. There is an aggregate COUNT function and also an analytical function of COUNTY. (Almost all aggregate functions have analytical counterparts).How can you tell if a function is used as an aggregate function or Analytics? The analytic form will be "OVER (
)" after his altercation; the overall shape will not be.
PARTITION BY is one of the elements that may form part of the analytical clause.
"PARTITION BY x, y ' in an analuytic function corresponds to" GROUP BY x, y "when using functions aggreggate.You can get the same results for a large number of problems using either global or analytical of a function versions.
For example, both versions global and analytical County can tell you that vistied office only 1 customer 1 April 1, but 2 clients visited the office 2 April 2.
If you use the aggregation function ACCOUNT and ' GROUP BY Office, tran_date ', as John suggested, you will get only one line for each distinct combination of office and tran_date. In other words, even if there are 3 rows of your table where office = 1 and tran_date = April 1, the result set will have onely a row where office = 1 and tran_date = 1 April.
Because it is exactly what you want, you can use the aggregate COUNT fucntion, as shown in John.If you use the analytical ACCOUNT function, there will be a line of output for each row in your table.
So with the sample data you posted, this query:SELECT office , tran_date , COUNT (DISTINCT customer) OVER ( PARTITION BY office , tran_date ) AS cnt FROM table_x;
will these results:
. OFFICE TRAN_DATE CNT ---------- ----------- ---------- 1 01-APR-2009 1 1 01-APR-2009 1 1 01-APR-2009 1 1 02-APR-2009 1 2 02-APR-2009 2 2 02-APR-2009 2 2 02-APR-2009 2
To get the exact results you want, you can use SELECT DISTINCT, like this:
SELECT DISTINCT office , COUNT (DISTINCT customer) OVER ...
-
A question about the analytical function used with the GROUP BY clause in SHORT
Hi all
I created the following table named myenterprise
If I want to find which is the total sales by city? I'll run the following queryCITY STOREID MONTH_NAME TOTAL_SALES ---------- ---------- ---------- ---------------------- paris id1 January 1000 paris id1 March 7000 paris id1 April 2000 paris id2 November 2000 paris id3 January 5000 london id4 Janaury 3000 london id4 August 6000 london id5 September 500 london id5 November 1000
that works very well and produces the expected result, i.e.SELECT city, SUM(total_sales) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY;
Now in one of my books SQL (Mastering Oracle SQL) I found another method by using the SUM, but this time as an analytic function. Here's what the method of the book suggests as an alternative to the problem:CITY TOTAL_SALES_PER_CITY ---------- ---------------------- london 10500 paris 17000
I know that the analytic functions are executed after the GROUP BY clause has been transformed completely and Unlike regular aggregate functions, they return their result for each line belonging to the partitions specified in the partition clause (if there is a defined partition clause).SELECT city, SUM(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY;
Now my problem is that I do not understand what we have to use two functions SUM? If we only use one only, i.e.
This generates the following error:SELECT city, SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY;
The error is generated for the line 2 column 11 which is, for the expression SUM (total_sales), well it's true that total_sales does not appear in the GROUP BY clause, but this should not be a problem, it has been used in an analytical function, so it is evaluated after the GROUP BY clause.Error starting at line 2 in command: SELECT city, SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY FROM myenterprise GROUP BY city ORDER BY city, TOTAL_SALES_PER_CITY Error at Command Line:2 Column:11 Error report: SQL Error: ORA-00979: not a GROUP BY expression 00979. 00000 - "not a GROUP BY expression" *Cause: *Action:
So here's my question:
Why use SUM (SUM (total_sales)) instead of SUM (total_sales)?
Thanks in advance!
:)
In case you are interested, that's my definition of the table:
Edited by: dariyoosh on April 9, 2009 04:51DROP TABLE myenterprise; CREATE TABLE myenterprise( city VARCHAR2(10), storeid VARCHAR2(10), month_name VARCHAR2(10), total_sales NUMBER); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id1', 'January', 1000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id1', 'March', 7000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id1', 'April', 2000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id2', 'November', 2000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('paris', 'id3', 'January', 5000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id4', 'Janaury', 3000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id4', 'August', 6000); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id5', 'September', 500); INSERT INTO myenterprise(city, storeid, month_name, total_sales) VALUES ('london', 'id5', 'November', 1000);
It is clear that thet Analytics is reduntant here...
You can even use AVG or any analytic function...SQL> SELECT city, 2 avg(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY 3 FROM myenterprise 4 GROUP BY city 5 ORDER BY city, TOTAL_SALES_PER_CITY; CITY TOTAL_SALES_PER_CITY ---------- -------------------- london 10500 paris 17000
-
Cannot use analytical functions such as lag/lead in odi components 12 c except in the expression
Hi I am a beginner of ODI 12 c
I'm trying to get the last two comments made on the product for a given product id. and load them into a target.
I have a source table something like
Product SR_NO comments LAST_UPDATED_TS
1 good car 2015/05/15 08:30:25
1 car average 2015/05/15 10:30:25
Jeep 2 super 2015/05/15 11:30:25
1 car bad 2015/05/15 11:30:25
Jeep 2 horrible 2015/05/15 09:30:25
Jeep 2 excellent 2015/05/15 12:30:25
I want a target table based on their last timestamp updated as (last two comments)
SR_NO Comment1 Comment2
1 bad average
2 super excellent
I used the logic below to get records in SQL Developer but in ODI 12 c, I'm not able to do this by mapping a source to the target table by applying analytical functions to the columns in the target table. Can someone help me solve this problem
SELECT * FROM)
SELECT SR_NO Comment1, LAG(Comment1,1,) ON Comment2 (SR_NO ORDER BY LAST_UPDATED_TS ASC PARTITION),
ROW_NUMBER() ON RN (SCORE FROM SR_NO ORDER BY LAST_UPDATED_TS DESC)
FROM Source_table
) M
WHERE RN = 1
;
UM, I'm afraid that ODI puts the filter too early in the request, if it generates:
SELECT * FROM)
SELECT SR_NO Comment1, LAG(Comment1,1,) ON Comment2 (SR_NO ORDER BY LAST_UPDATED_TS ASC PARTITION),
ROW_NUMBER() ON RN (SCORE FROM SR_NO ORDER BY LAST_UPDATED_TS DESC)
FROM Source_table
WHERE RN = 1
) M
;
Instead of:
SELECT * FROM)
SELECT SR_NO Comment1, LAG(Comment1,1,) ON Comment2 (SR_NO ORDER BY LAST_UPDATED_TS ASC PARTITION),
ROW_NUMBER() ON RN (SCORE FROM SR_NO ORDER BY LAST_UPDATED_TS DESC)
FROM Source_table
) M
WHERE RN = 1
;
Even by changing the 'run on Hint"of your component of the expression to get there on the source, the request will stay the same.
I think the easiest solution for you is to put everything before the filter in a reusable mapping with a signature of output. Then drag this reusable in your mapping as the new source and check the box "subselect enabled."
Your final mapping should look like this:
It will be useful.
Kind regards
JeromeFr
-
Nth salary using the analytic function
I use under function to calculate second highest with empno and deptno salary.
Is it possible to get the same result with another query without using Assembly only analytical functions condition.using and windows function is possible to get the desired output?
SELECT e.empno,
e.DEPTNO,
tmp. SAL as second_higher_salary
FROM emp e,.
(SELECT Empno,
DEPTNO,
SAL,
DENSE_RANK() (PARTITION BY deptno ORDER of sal) AS rnk
WCP
) tmp
WHERE tmp.deptno = e.deptno
and tmp.rnk = 2
EMPNO DEPTNO SAL
---------- ---------- ----------
7934 10 2450
7782 10 2450
7839 10 2450
7876 20 1100
7369 20 1100
7902 20 1100
7788 20 1100
7566 20 1100
7900 30 1250
7844 30 1250
7654 30 1250
7521 30 1250
7499 30 1250
7698 30 1250
7900 30 1250
7844 30 1250
7654 30 1250
7521 30 1250
7499 30 1250
7698 30 1250
Here's my solution:
Select empno,
DEPTNO,
FIRST_VALUE (sal) (PARTITION BY deptno ORDER by sal desc)
de)
SELECT EmpNo,
DEPTNO,
Decode (DENSE_RANK () OVER (PARTITION BY deptno order by sal desc), 1,-sal, sal) sal
WCP
)
/
EMPNO DEPTNO FIRST_VALUE (SAL) OVER (PARTITIONBYDEPTNOORDERBYSALDESC) ---------- ---------- -----------------------------------------------------
7782 10 2450 7934 10 2450 7839 10 2450 7566 20 2975 7876 20 2975 7369 20 2975 7788 20 2975 7902 20 2975 7499 30 1600 7844 30 1600 7654 30 1600 7521 30 1600 7900 30 1600 7698 30 1600
Maybe you are looking for
-
Diffence between firefox functionality on xp and windows 7
I just want to know the difference between the feature and the dependence on the two bones. and y at - it any thing change setting of Firefox on windows xp or 7 l.
-
Hello I have a 200 Mbps TWC service. I use TWC provided modem Arris 1070a (NAT = bridge) and have an Airport Express connected via Ethernet to my wireless router. When I connect my macbook pro directly to the modem arris via ethernet, I get over 200
-
HP Pavilion Slimline s3320f desktop PC Windows Vista My brother tried to get my hard drive to a new computer and accedentally erased the hard drive. the computer has been saved before this wipe. I was wondering how to restore or to access saved inf
-
Scan convert ms word (.doc) file.
Is there any software by which I can convert my scanned images (text) to the ms word doc (.doc) file?
-
How to create a backup to a Windows xp pre-installed cd. I have no floppy and disk of origin not provided. Hard drive is defective so have to save