Analytical function - County not null record
Hi all
Is it possible to count the column records is not null using anlaytical?
Count (Column = 1) on)
Thank you.
«count (col) over (...)» counts only non-null values...
Some examples of data with tables to create and insert queries so that we can help you...
See you soon,.
Manik.
Tags: Database
Similar Questions
-
FIRST analytical functions returns the null line
The following query returns a null line when there is no such thing as a line for the predicate. Is it a bug or expected behaviour. If so what is the meaning of the null row, is it not logical?
SELECT NVL (max (ah.fyr_end_dt) KEEP (DENSE_RANK FIRST ORDER BY ah.as_of_dt DESC), ' RETURNED NULL')
Of account_history ah
WHERE
Ah.acct_id = 999
AND trunc (ah.as_of_dt) < = 31 December 08 '
;Hello
user4900730 wrote:
Moreover, in my example how I distinguish the case where a line really exists, but the column is null when there is no such thing as a line and the FIRST function returns the same value null? Hopefullly I should be able to do it in a single SQL and know the difference?COUNT (*) > 0, but COUNT (col_x) = 0, then there is a line, but col_x happened to be null.
For example, the following query shows that there is 1 row in the group with the lowest name ("ADAMS"), but the column comm in all ranks of this group is null:
SELECT COUNT (*) KEEP (DENSE_RANK FIRST ORDER BY ename) AS total_cnt , COUNT (comm) KEEP (DENSE_RANK FIRST ORDER BY ename) AS comm_cnt FROM scott.emp ;
Output:
TOTAL_CNT COMM_CNT ---------- ---------- 1 0
The employee whose highest name ("WARD") has a number in the comm column.
-
Purpose of the ORDER BY clause in the analytic function Min Max
I was always using analytical functions like Min Max without ORDER BY clause. But today I used with the ORDER BY clause. The results are very different. I would like to know the purpose of the ORDER BY clause in Min, Max and analogues of analytical functions.user10566312 wrote:
I was always using analytical functions like Min Max without ORDER BY clause. But today I used with the ORDER BY clause. The results are very different. I would like to know the purpose of the ORDER BY clause in Min, Max and analogues of analytical functions.It is a good point that many developers are not so aware. As far as I understand it the way it works.
Some analytical functions do not need an order by or windowing clause (SUM, COUNT, MIN, etc.). If there is no specified window, then the full score is the window.
As soon as you add a command also add you a windowing clause. This window has the default value of 'rank ofrowsbetween unbounded preceding and current_row. So as soon as you add an order by clause, you get a sliding window.Documentation: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm
windowing_clause
...
You cannot specify this clause unless you specified the order_by_clause. Window limits defined by the clause RANGE you can not specify only a single expression to the > order_by_clause. Please refer to 'Restrictions on the ORDER BY Clause'.example of
with testdata as (select 10 numval, level lv from dual connect by level < 10) select lv, numval, sum(numval) over () sum1, sum(numval) over (order by lv) sum2 from testdata; LV NUMVAL SUM1 SUM2 -- ------ ---- ---- 1 10 90 10 2 10 90 20 3 10 90 30 4 10 90 40 5 10 90 50 6 10 90 60 7 10 90 70 8 10 90 80 9 10 90 90
Published by: Sven w. on 25 Sep 2012 16:57 - default behavior has been corrected. Thanks to Chris
-
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.
-
Question
I want to record with < alt > < s > in the Exact program online. This function does not work. This is the first time I use this program with firefox.edit, escaped mod < s > in order to avoid the line through question
A web page can be defined a "accesskey" for an item. Unlike IE/Chrome/Safari, who use the Alt key only, Firefox requires pressing Alt and Shift to activate the element. In other words, try
ALT + SHIFT + S
and see if it works.
I don't know of any way to change this so that the change is not necessary. There may be an add-on?
-
Hello
In the 4.0.0.833 version the funcion getProperty() returns NULL when the dynamic propertyare not out,
e.g. VRFDA = table.getProperty ("Text"); -Returns a null value if the dynamic property 'Text' does not exist. The Variable VRFDA is nothing
I have version 4.1.1.888 and the GetFilter() function returns DO NOT null when the dynamic property does not exist.
Could you tell me what value returns the GetFilter() function when the dynamic property does NOT exist?
Thank you
In version 4.1 the getProperty function will return an empty string if the dynamic property does not exist.
David
-
Report Builder 6i do not recognize the analytical functions
Hi all, in an attempt to speed up a slow query, I applied the analytical function to it. I can save the query in the generator without any problem, however, I can't create data between this request and other links. After I have comment on the analytical function, data bindings can be made. My colleague says Report Builder 6i is too old so he can recognize only the ANSI SQL syntax. Since our server DB uses Oracle 10 g 2, is there a way for the generator of reports to identify and compile syntax of Oracle 10 g?
Thank you very much.Hello
Your colleague is right. Even if the SQL query is executed by the DB server, reports must analyze the SQL query.
The SQL parser included in reports 6i-based 8.0.6
You can see this version using the report designer:
Menu: Help-> on Report Builder...
ORACLE Server Release 8.0.6.0.0
Concerning
-
Problem with analytical function for date
Hi all
ORCL worm:
Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
PL/SQL Release 11.2.0.2.0 - Production
"CORE 11.2.0.2.0 Production."
AMT for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
I have a problem with the analtical for the date function. I'm trying to group records based on timestamp, but I'm failing to do.
Could you please help me find where I'm missing.
THXThis is the subquery. No issue with this. I'm just posting it for reference. select sum(disclosed_cost_allocation.to_be_paid_amt) amt, substr(reference_data.ref_code,4,10) cd, to_char(external_order_status.status_updated_tmstp, 'DD-MON-YYYY HH24:MI:SS') tmstp, DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID id FROM Deal.Fee_Mapping_Definition , Deal.Fee_Index_Definition , Deal.Fee_Closing_Cost_Item, Deal.Closing_Cost, Deal.Document_Generation_Request, deal.PRODUCT_REQUEST, deal.External_Order_Request, deal.External_Order_Status, deal. DISCLOSED_CLOSING_COST, deal.DISCLOSED_COST_ALLOCATION, deal.reference_data WHERE Fee_Mapping_Definition.Fee_Code = Fee_Index_Definition.Fee_Code AND Fee_Index_Definition.Fee_Index_Definition_Id = Fee_Closing_Cost_Item.Fee_Index_Definition_Id AND Fee_Closing_Cost_Item.Closing_Cost_Id = Closing_Cost.Closing_Cost_Id AND CLOSING_COST.PRODUCT_REQUEST_ID = Document_Generation_Request.Product_Request_Id AND closing_cost.product_request_id = product_request.product_request_id AND Product_Request.Deal_Id = External_Order_Request.Deal_Id AND external_order_request.external_order_request_id = external_order_status.external_order_request_id AND external_order_request.external_order_request_id = disclosed_closing_cost.external_order_request_id AND DISCLOSED_CLOSING_COST. DISCLOSED_CLOSING_COST_ID = DISCLOSED_COST_ALLOCATION.DISCLOSED_CLOSING_COST_ID AND Fee_Index_Definition.Fee_Index_Definition_Id = Disclosed_Closing_Cost.Fee_Index_Definition_Id AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id = Reference_Data.Reference_Data_Id AND Document_Generation_Request.Document_Package_Ref_Id IN (7392 ,2209 ) AND External_Order_Status.Order_Status_Txt = ('GenerationCompleted') AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id IN ( 7789, 7788,7596 ) AND FEE_MAPPING_DEFINITION.DOCUMENT_TYPE_REF_ID = 1099 AND Document_Generation_Request.Product_Request_Id IN (SELECT PRODUCT_REQUEST.PRODUCT_REQUEST_id FROM Deal.Disclosed_Cost_Allocation, Deal.Disclosed_Closing_Cost, DEAL.External_Order_Request, DEAL.PRODUCT_REQUEST, Deal.Scenario WHERE Disclosed_Cost_Allocation.Disclosed_Closing_Cost_Id = Disclosed_Closing_Cost.Disclosed_Closing_Cost_Id AND Disclosed_Closing_Cost.External_Order_Request_Id = External_Order_Request.External_Order_Request_Id AND External_Order_Request.Deal_Id = Product_Request.Deal_Id AND product_request.scenario_id = scenario.scenario_id AND SCENARIO.SCENARIO_STATUS_TYPE_REF_ID = 7206 AND product_request.servicing_loan_acct_num IS NOT NULL AND product_request.servicing_loan_acct_num = 0017498379 --AND Disclosed_Cost_Allocation.Disclosed_Cost_Allocation_Id = 5095263 ) GROUP BY DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID, External_Order_Status.Status_Updated_Tmstp, Reference_Data.Ref_Code, disclosed_cost_allocation.to_be_paid_amt order by 3 desc, 1 DESC; Result: 2000 1304-1399 28-JUL-2012 19:49:47 6880959 312 1302 28-JUL-2012 19:49:47 6880958 76 1303 28-JUL-2012 19:49:47 6880957 2000 1304-1399 28-JUL-2012 18:02:16 6880539 312 1302 28-JUL-2012 18:02:16 6880538 76 1303 28-JUL-2012 18:02:16 6880537 But, when I try to group the timestamp using analytical function, select amt ,cd ,rank() over(partition by tmstp order by tmstp desc) rn from (select sum(disclosed_cost_allocation.to_be_paid_amt) amt, substr(reference_data.ref_code,4,10) cd, to_char(external_order_status.status_updated_tmstp, 'DD-MON-YYYY HH24:MI:SS') tmstp, DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID id FROM Deal.Fee_Mapping_Definition , Deal.Fee_Index_Definition , Deal.Fee_Closing_Cost_Item, Deal.Closing_Cost, Deal.Document_Generation_Request, deal.PRODUCT_REQUEST, deal.External_Order_Request, deal.External_Order_Status, deal. DISCLOSED_CLOSING_COST, deal.DISCLOSED_COST_ALLOCATION, deal.reference_data WHERE Fee_Mapping_Definition.Fee_Code = Fee_Index_Definition.Fee_Code AND Fee_Index_Definition.Fee_Index_Definition_Id = Fee_Closing_Cost_Item.Fee_Index_Definition_Id AND Fee_Closing_Cost_Item.Closing_Cost_Id = Closing_Cost.Closing_Cost_Id AND CLOSING_COST.PRODUCT_REQUEST_ID = Document_Generation_Request.Product_Request_Id AND closing_cost.product_request_id = product_request.product_request_id AND Product_Request.Deal_Id = External_Order_Request.Deal_Id AND external_order_request.external_order_request_id = external_order_status.external_order_request_id AND external_order_request.external_order_request_id = disclosed_closing_cost.external_order_request_id AND DISCLOSED_CLOSING_COST. DISCLOSED_CLOSING_COST_ID = DISCLOSED_COST_ALLOCATION.DISCLOSED_CLOSING_COST_ID AND Fee_Index_Definition.Fee_Index_Definition_Id = Disclosed_Closing_Cost.Fee_Index_Definition_Id AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id = Reference_Data.Reference_Data_Id AND Document_Generation_Request.Document_Package_Ref_Id IN (7392 ,2209 ) AND External_Order_Status.Order_Status_Txt = ('GenerationCompleted') AND Fee_Mapping_Definition.Document_Line_Series_Ref_Id IN ( 7789, 7788,7596 ) AND FEE_MAPPING_DEFINITION.DOCUMENT_TYPE_REF_ID = 1099 AND Document_Generation_Request.Product_Request_Id IN (SELECT PRODUCT_REQUEST.PRODUCT_REQUEST_id FROM Deal.Disclosed_Cost_Allocation, Deal.Disclosed_Closing_Cost, DEAL.External_Order_Request, DEAL.PRODUCT_REQUEST, Deal.Scenario WHERE Disclosed_Cost_Allocation.Disclosed_Closing_Cost_Id = Disclosed_Closing_Cost.Disclosed_Closing_Cost_Id AND Disclosed_Closing_Cost.External_Order_Request_Id = External_Order_Request.External_Order_Request_Id AND External_Order_Request.Deal_Id = Product_Request.Deal_Id AND product_request.scenario_id = scenario.scenario_id AND SCENARIO.SCENARIO_STATUS_TYPE_REF_ID = 7206 AND product_request.servicing_loan_acct_num IS NOT NULL AND product_request.servicing_loan_acct_num = 0017498379 --AND Disclosed_Cost_Allocation.Disclosed_Cost_Allocation_Id = 5095263 ) GROUP BY DISCLOSED_CLOSING_COST.DISCLOSED_CLOSING_COST_ID, External_Order_Status.Status_Updated_Tmstp, Reference_Data.Ref_Code, disclosed_cost_allocation.to_be_paid_amt order by 3 desc, 1 DESC); Result: 312 1302 1 2000 1304-1399 1 76 1303 1 312 1302 1 2000 1304-1399 1 76 1303 1 Required output: 312 1302 1 2000 1304-1399 1 76 1303 1 312 1302 2 2000 1304-1399 2 76 1303 2
Rod.Hey, Rod,
My guess is that you want:
, dense_rank () over (order by tmstp desc) AS rn
RANK means you'll jump numbers when there is a link. For example, if all 3 rows have the exact same last tmstp, all 3 rows would be assigned number 1, GRADE would assign 4 to the next line, but DENSE_RANK attributes 2.
"PARTITION x" means that you are looking for a separate series of numbers (starting with 1) for each value of x. If you want just a series of numbers for the entire result set, then do not use a PARTITION BY clause at all. (PARTITION BY is never required.)
Maybe you want to PARTITIONNER IN cd. I can't do it without some examples of data, as well as an explanation of why you want the results of these data.
You certainly don't want to PARTITION you BY the same expression ORDER BY; It simply means that all the lines are tied for #1.I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Simplify the problem as much as possible.
Always tell what version of Oracle you are using.
See the FAQ forum {message identifier: = 9360002}Published by: Frank Kulash, August 1, 2012 13:20
-
Need help to resolve the query by using analytic functions
Hello
I need help to solve this problem, I tried an analytical function but could not solve the problem.
I have three table as illustrated below the table is filled with a flat file. The records are arranged sequentailly based on the name of the file.
The first record of the game based on EIN goes to TAB_RCE
the following records then goes to TAB_RCW
and last save of the game based on EIN goes to the RCT table
How can I make groups and
assign a
EIN * 12345 * line number * 02, 03, 04 * in the table TAB_RCW and * 05 * in the table TAB_RCT
EIN * 67890 * line number * 07, 08, 09,10 * in the table TAB_RCW and * 11 * in the table TAB_RCT
and so on...
Thank you
Rajesh
TAB RCE_--------------------------------------------------------------
LineNumber EIN FILENAME TYPE
-----
01 12345 ABC NCE. TXT
06 67890 ABC NCE. TXT
12 76777 ABC NCE. TXT
-----
TAB_RCW
-----
LineNumber TYPE SSN FILENAME
-----
02 22222 ABC RCW. TXT
03 33333 ABC RCW. TXT
04 44444 ABC RCW. TXT
07 55555 ABC RCW. TXT
08 66666 ABC RCW. TXT
09 77777 ABC RCW. TXT
10 88888 ABC RCW. TXT
13 99998 ABC RCW. TXT
14 99999 ABC RCW. TXT
-----
TAB_RCT
-----
NAME OF THE FILE OF TYPE LINENUMBER
-----
RCT 05 ABC. TXT
RCT 11 ABC. TXT
RCT 15 ABC. TXT
-----SQL> with TAB_RCE as ( 2 select 'RCE' rtype,'01' linenumber, '12345' EIN,'ABC.TXT' FILENAME from dual union all 3 select 'RCE','06','67890','ABC.TXT' from dual union all 4 select 'RCE','12','76777','ABC.TXT' from dual 5 ), 6 TAB_RCW as ( 7 select 'RCW' rtype,'02' linenumber,'22222' ssn,'ABC.TXT' FILENAME from dual union all 8 select 'RCW','03','33333','ABC.TXT' from dual union all 9 select 'RCW','04','44444','ABC.TXT' from dual union all 10 select 'RCW','07','55555','ABC.TXT' from dual union all 11 select 'RCW','08','66666','ABC.TXT' from dual union all 12 select 'RCW','09','77777','ABC.TXT' from dual union all 13 select 'RCW','10','88888','ABC.TXT' from dual union all 14 select 'RCW','13','99998','ABC.TXT' from dual union all 15 select 'RCW','14','99999','ABC.TXT' from dual 16 ), 17 TAB_RCT as ( 18 select 'RCT' rtype,'05' linenumber,'ABC.TXT' FILENAME from dual union all 19 select 'RCT','11','ABC.TXT' from dual union all 20 select 'RCT','15','ABC.TXT' from dual 21 ) 22 select rtype, 23 last_value(ein ignore nulls) over(partition by filename order by linenumber) ein, 24 linenumber, 25 ssn 26 from ( 27 select rtype, 28 linenumber, 29 ein, 30 to_char(null) ssn, 31 filename 32 from TAB_RCE 33 union all 34 select rtype, 35 linenumber, 36 to_char(null) ein, 37 ssn, 38 filename 39 from TAB_RCW 40 union all 41 select rtype, 42 linenumber, 43 to_char(null) ein, 44 to_char(null) ssn, 45 filename 46 from TAB_RCt 47 ) 48 order by linenumber 49 / RTY EIN LI SSN --- ----- -- ----- RCE 12345 01 RCW 12345 02 22222 RCW 12345 03 33333 RCW 12345 04 44444 RCT 12345 05 RCE 67890 06 RCW 67890 07 55555 RCW 67890 08 66666 RCW 67890 09 77777 RCW 67890 10 88888 RCT 67890 11 RTY EIN LI SSN --- ----- -- ----- RCE 76777 12 RCW 76777 13 99998 RCW 76777 14 99999 RCT 76777 15 15 rows selected. SQL>
SY.
-
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
-
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.
-
Why the different values for an analytic function of the same group/game
I have the suite of table I'll be using.
Select * from table1;
REC_ID | STATUS | DATE_FROM | DATE_TO
1. C | 7 January 2015 |
2. H | December 3, 2014. 6 January 2015
3. H | October 3, 2014. December 2, 2014
4. H | May 30, 2014. October 2, 2014
5. H | May 29, 2014 | May 29, 2014
6. H | April 16, 2014 | May 28, 2014
7. H | Tuesday, April 25, 2007 April 15, 2014
INSERT statement if you need.
TOGETHER TO DEFINE
CREATE THE TABLE1 TABLE:
(
NUMBER OF REC_ID,
VARCHAR2 (1 BYTE) STATUS NOT NULL,.
DATE_FROM DATE NOT NULL,
DATE OF DATE_TO
);
Insert into TABLE1
(REC_ID, STATUS, DATE_FROM)
Values
(1, 'C', TO_DATE (7 JANUARY 2015 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into TABLE1
(REC_ID, STATUS, DATE_FROM, DATE_TO)
Values
(2, 'H', TO_DATE (3 DECEMBER 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (6 JANUARY 2015 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into TABLE1
(REC_ID, STATUS, DATE_FROM, DATE_TO)
Values
(3, 'H', TO_DATE (3 OCTOBER 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (2 DECEMBER 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into TABLE1
(REC_ID, STATUS, DATE_FROM, DATE_TO)
Values
(4, 'H', TO_DATE (MAY 30, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (2 OCTOBER 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into TABLE1
(REC_ID, STATUS, DATE_FROM, DATE_TO)
Values
(5, 'H', TO_DATE (29 MAY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (29 MAY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into TABLE1
(REC_ID, STATUS, DATE_FROM, DATE_TO)
Values
(6, 'H', TO_DATE (APRIL 16, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (28 MAY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into TABLE1
(REC_ID, STATUS, DATE_FROM, DATE_TO)
Values
(7, 'H', TO_DATE (APRIL 25, 2007 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), TO_DATE (APRIL 15, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'));))
COMMIT;
I will exercise more analytical query...
Select rec_id date_from, date_to, status,
min (date_from) over (partition by order of status by date_from desc) min_dt_from_grp,
ROW_NUMBER() over (partition by order of status by date_from desc) rownumberdesc,
ROW_NUMBER() over (partition by order of status by ASC date_from) rownumberasc
FROM table1;
the query result
REC_ID | DATE_FROM | DATE_TO | STATUS | MIN_DT_FROM_GRP | ROWNUMBERDESC | ROWNUMBERASC
1. 7 January 2015 | C | 7 January 2015 | 1. 1
2. December 3, 2014. 6 January 2015 | H | December 3, 2014. 1. 6
3. October 3, 2014. December 2, 2014 | H | October 3, 2014. 2. 5
4. May 30, 2014. October 2, 2014 | H | May 30, 2014. 3. 4
5. May 29, 2014 | May 29, 2014 | H | May 29, 2014 | 4. 3
6. April 16, 2014 | May 28, 2014. H | April 16, 2014 | 5. 2
7. Tuesday, April 25, 2007 April 15, 2014. H | Tuesday, April 25, 2007 6. 1
If you look at the output above, it dates back in the min_dt_from_grp column.
MY question is if the analytical function calculates for a particular/set group, which is by statute and for what min (date_from) partition is 25-apr-2007 for the GROUP H (Status column), then why I have different values returned by the query above in the min_dt_from_grp column.
Hello
Because you have specified an ORDER BY clause for the analytical function. In doing so, you calculate the rows on a window. Since you have not specified a windowing clause, the default applies:
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
-
Hello
I have two tables b rates and transactions (b).
For each b.FS, I want to know new amount (b.amt time a.rate to the corresponding line of FS b and if a.na is valid based on the flag of the exclusion and the interval defined in the table's).
It is much easier to explain with an example.
So here we go...
Exclude_flag = E (exclude): for b.fs = 433638, b.na = 80000. I have 2 lines in the table for this fs. Both have E exclude_flag (exclude). I want to go on all the lines in this FS in the table in a query and I return only one row in the result, if and only if b.na falls out of scope of a.na_min_value and a.na_max_values. In this example, it falls outside the range excluded for both lines (first two lines of the table a).
Similarly, exclude_flag = I (Include). for b.fs = 432828, b.na = 17200. I have 2 lines in the table for this fs. Both have an exclude_flag of I (include). I want to go on all the lines in this FS in the table in a query and I return only one row in the result, if and only if b.na is between a.na_min_value and a.na_max_values. In this example, it falls in the range of both the range include for the two lines (line 6 and 7 of the table a).
The following query gives me two lines for each b.fs. It is possible to get what I'm looking for simply using sql (possibly write the analytical function?) or I have to write the pl/sql routine for this?
WITH rates_table
Did YOU (select ' E' include_exclude_flag, "81000 ' na_min_value, na_max_value '81999', '433638' FS, 0.8 of double rate
UNION
Select 'E' include_exclude_flag, na_min_value '84000', na_max_value '84999', '433638' FS, 0.8 of double rate
UNION
Select 'I' include_exclude_flag, na_min_value '12000', na_max_value '12999', '432828' FS, rate 0.25 double
UNION
Select 'I' include_exclude_flag, na_min_value '13000', na_max_value '13999', '432828' FS, rate 0.25 double
UNION
Select 'I' include_exclude_flag, na_min_value '15000', na_max_value '15000', '432828' FS, rate 0.25 double
UNION
Select 'I' include_exclude_flag, na_min_value '16100', na_max_value '18000', '432828' FS, rate 0.25 double
UNION
Select 'I' include_exclude_flag, '17100' na_min_value, na_max_value '18000', '432828' FS, rate 0.25 double
UNION
Select 'I' include_exclude_flag, na_min_value '02440', na_max_value '02470', '016532' FS, 0.35 rate double
UNION
Select 'E' include_exclude_flag, na_min_value ' 21000 ', '21000' na_max_value, ' 200020' FS, 0.35 double rate).
transaction_table AS
(select '433638' FS '80000' NA, 300 double amt)
Union
Select '432828' FS '17200' NA, amt 500 double
)
Select * from rates_table a, transaction_table b
where 1 = 1
and ((b.na PAS entre a.na_min_value et a.na_max_value et a.include_exclude_flag = «E») GOLD ())
b.na between a.na_min_value and a.na_max_value and a.include_exclude_flag = 'I'))
and b.fs = a.fs
;
Any help is greatly appreciated. I use oracle 11i
@OP,
For this kind of problems, we get the number of rows that satisfy the required conditions or who do not meet the required conditions. And then eliminate the line that should be eliminated.
As below, I calculate four counts (number of join lines)
EOBCNT - excluded and Out of Bound
EIBCNT - excluded and in the limit
IOBCNT - included and Out of Bound
IIBCNT - included and within the limits
Once those are calculated, simply return the lines that have EIBCNT and IOBCNT are zero.
For Ex:
> WITH
rates_table
AS LONG AS)
Select 'E' include_exclude_flag, na_min_value '79999', na_max_value '79999', '433638' FS, 0.8 double UNION rates
-Select 'E' include_exclude_flag, na_min_value ' 79999', na_max_value '80000', '433638' FS, 0.8 double UNION rate - TEST - THE
-If you uncomment the last line and then 433638 will not be returned
Select 'E' include_exclude_flag, "81000 ' na_min_value, na_max_value '81999', '433638' FS, 0.8 double UNION rates
Select 'E' include_exclude_flag, na_min_value '84000', na_max_value '84999', '433638' FS, 0.8 double UNION rates
Select 'I' include_exclude_flag, na_min_value '12000', na_max_value '12999', '432828' FS, 0.25 rate double UNION
Select 'I' include_exclude_flag, na_min_value '13000', na_max_value '13999', '432828' FS, 0.25 rate double UNION
Select 'I' include_exclude_flag, na_min_value '15000', na_max_value '15000', '432828' FS, 0.25 rate double UNION
Select 'I' include_exclude_flag, na_min_value '16100', na_max_value '18000', '432828' FS, 0.25 rate double UNION
Select 'I' include_exclude_flag, '17100' na_min_value, na_max_value '18000', '432828' FS, 0.25 rate double UNION
Select 'I' include_exclude_flag, na_min_value '02440', na_max_value '02470', '016532' FS, 0.35 rate double UNION
Select 'E' include_exclude_flag, na_min_value ' 21000 ', '21000' na_max_value, ' 200020' FS, 0.35 double rate).
transaction_table AS
(select '433638' FS '80000' NA, amt 300 Union double
Select '432828' FS '17200' NA, amt 500 double
)
getcnts as)
SELECT a.*
b.na, b.amt
, sum (case when (b.na NOT BETWEEN a.na_min_value)
AND a.na_max_value
AND a.include_exclude_flag = 'E '.
end) then 1 else 0) on (a.fs partition) Eobcnt
, sum (case when (b.na NOT BETWEEN a.na_min_value)
AND a.na_max_value
AND a.include_exclude_flag = 'I '.
end) then 1 else 0) on (a.fs partition) Iobcnt
, sum (case when (b.na BETWEEN a.na_min_value)
AND a.na_max_value
AND a.include_exclude_flag = 'E '.
end) then 1 else 0) on (a.fs partition) Eibcnt
, sum (case when (b.na BETWEEN a.na_min_value)
AND a.na_max_value
AND a.include_exclude_flag = 'I '.
end) then 1 else 0) on (a.fs partition) Iibcnt
OF rates_table one
transaction_table b
WHERE b.fs = a.fs
)
getrows as)
Select x.*, row_number() on
(partition by order of fs with null desc) getcnts rn x
where IOBCNT = 0 and eibcnt = 0 - remove lines that are not needed (IF and ONLY if)
)
Select * from getrows
where rn = 1 - to limit a SINGLE row (arbitrarily)
INCLUDE_EXCLUDE_FLAG NA_MIN_VALUE NA_MAX_VALUE FS RATE NA AMT EOBCNT IOBCNT EIBCNT IIBCNT RN
-------------------- ------------ ------------ ------ ---------- ----- ---------- ---------- ---------- ---------- ---------- ----------
433638 84999 84000.8 E 80000 300 3 0 0 0 1
I hope this helps.
-
Order of evaluation of analytic function
Hello
have question quite like this:
with
-This query selects a 'representative' acct_id by Group (about 300 lines in total)
acct_repres as
(
Select distinct acct_id, origin_id, acct_parm_id of
(
Select a.*
source_id
, dense_rank() over (partition by order source_id by nulls first, acct_id acct_nbr origin_id) as odr
account a join account_parm on (a.parm_id = ap.acct_parm_id) ap
)
where odr = 1
)
Select col1
col2
, (select accct_id from ar acct_repres where ar.acct_parm_id = t2.acct_parm_id) col3
, col4 (select count (1) of acct_repres)
of une_table t1
Join other_table t2 on (...)
And here it is. "Acct_repres" subquery returns more than 300 lines when it is run separately. But when it is used in CTE sometimes (depending on the execution plan) she seems to have that one line - the value in the column col4 is '1 ',.
While the value of col3 is NULL for most of the cases.
It looks like the the dense_rank function and the State 'where odr = 1' are evaluated at the end.
When I use the hint to MATERIALIZE the result was the same.
But when I put the result of account_repres in the dedicated table and use this table instead of CTE output is correct.
What is a bug? Or I do something wrong?
PS: my version of db is 11 GR 1 material (11.1.0.7).
some unorganized comments:
-analytical functions are evaluated towards the end of the execution ("' the last set of operations performed in a query with the exception of the final
ORDER
BY
clause"- http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions004.htm")-but still the result of a SQL query must be deterministic, so I think that your results are not an expected behavior
-the CBO has some problems with common table expressions (http://jonathanlewis.wordpress.com/2012/05/24/subquery-factoring-7/) if they are of great assistance in the structuring of complex queries. In these cases, you can avoid problems by using inline views
-Your query uses the common table expressions in scalar subqueries and scalar subqueries are also likely to confuse the CBO. In addition, they are executed once for each row in your result set (or at least for each different correlation value) and can have a negative impact on the performance of the queries in many cases. Often, they can be replaced by outer joins.
-you say that the suspicion of materialization brings you an erroneous result: the indicator object (online) gives you the correct results?
Concerning
Martin Preiss
-
Return one row of an analytic function
Hello
I pulled the following query:
Select ID_STORNO, first_value (COD_CONTATTO) ON (Partition of COD_CONTATTO
order of COD_PRIORITY asc, desc FT_DAT_OPEN_CNT
rows between unbounded preceding and following unbounded)
as COD_CONTATTO_LAST
of WT_STR_ESG_CONTATTO;
The result is:
2160603 C1-H83J1N 2160603 C8-9FOHXJS 2258072 C1-H83J1N But I just need to take the following lines
2160603 C8-9FOHXJS 2258072 C1-H83J1N Because for the same value of ID_STORNO, I just need to get a value of COD_CONTATTO (to select the best value using COD_PRIORITY and FT_DAT_OPEN_CNT). What is wrong inside the query? I just use 2 or 3 times the oracle analytic functions.
Best regards
As SomeoneElse... you need a where clause clause in order to choose the ones you want.
To do this, the typical is to select a column that you use for this reason, such as:
"I want to just the first record in each group..."
Select id_storno, cod_contatto_last from)
Select ID_STORNO, first_value (COD_CONTATTO) ON (Partition of COD_CONTATTO
order of COD_PRIORITY asc, desc FT_DAT_OPEN_CNT
rows between unbounded preceding and following unbounded)
as COD_CONTATTO_LAST,
ROW_NUMBER() OVER (Partition of COD_CONTATTO
order of COD_PRIORITY asc, desc FT_DAT_OPEN_CNT
rows between unbounded preceding and following unbounded)
as rnum
of WT_STR_ESG_CONTATTO
)
where rnum = 1
/
I prefer to use rownumber in this case, so I always have a rnum = 1...
Usually, you must use the same partition/command by as your other folders (it is usually a good idea... maybe not, depending on your needs, however)
Maybe you are looking for
-
NB200-PLL25A built in 3G wireless F3507g works only with Optus 3 G
Hello I just wanted to know if anyone has managed to get the 3G modem with the Australian Optus 3 G on Xp or Windows 7? I put the sim card in the game (prepaid) AFN, etc, and while he sees the network Optus, it connects, I get the error message (0) c
-
Remember - this is a public forum so never post private information such as numbers of mail or telephone! Ideas: I need help how to solve this problem You have problems with programs Error messages Recent changes to your computer What you have alread
-
4645 HP printer-words/lines cut in the Middle
Hello the text printed in a few lines is cut off. the cartridges are full Thank you Avner
-
D drive disappears when Norton is installed (Code 10)
I put norton 360 m on my laptop with vista basic and my d drive went. I uninstalled norton, and she came back. several hours online with nixonraj (symantac rep) has not solved the problem. Code 10 is displayed on the system check original title: nort
-
I have a year 76 old friend Vietnamese who just accidentialy broke the remote at his TV NSX-40GT1 who stopped of course. We have so much trouble finding a replacement. What is his best bet? Thank you.