Pl help in query
I have a table arm. In that loan_number,change_begin_date and change_end_date are composite primary key.so i want only one data for loan_number as per this condition change_begin_date <= trunc(sysdate, 'mm')-1 and
change_end_date >= trunc(sysdate, 'mm') - 1
So how to write query?
select *
from arm
where trunc(sysdate,'mm') - 1 between change_begin_date and change_end_date;
if you mean, you want only one record then you should have another conditions. the above query might return more than one records...
or probably you mean something like this...
select * from arm
where (loan_number, change_begin_date, change_end_date) in
(select loan_number, change_begin_date, change_end_date
from arm
where trunc(sysdate,'mm') - 1 between change_begin_date and change_end_date
and rownum = 1);
Similar Messages
-
Hi Guru's
Can you please help me query tunning.
Database Version : Oracle 11g - 11.2.0.3
select distinct corporation_name custer_name,
glog_util.remove_domain(SHIP_BUY.SERVPROV_GID ) SCAC,
glog_util.remove_domain(ship_buy.shipment_gid) buy_shipment_gid,
F_Get_SELL_ID_STRING(SHIP_BUY.SHIPMENT_GID) sell_shipment_gid,
ship_buy.domain_name,
F_GET_ORDER_RELEASE_GID('B',SHIP_BUY.SHIPMENT_GID,0) ORDER_RELEASE_GID,
f_get_refnum_string('SHIPMENT', ship_buy.shipment_gid, 'MBOL_NUMBER_CLEANSED')MBOL_NUMBER,
F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID) POD_RECEIVED_DATE,
f_get_exp_accrue_amt(ship_buy.shipment_gid,'SHIPMENT') Total_accrual_amount
from shipment ship_buy,
invoice inv,
invoice_shipment si,
--voucher v,
corporation corp
where corp.domain_name=ship_buy.domain_name
and corp.is_domain_master='Y'
and 1=1
AND ship_buy.domain_name like 'UPS/CP/DFP/%'
and F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID) <= to_char(to_date('31-JUL-2013', 'DD-MON-YYYY'), 'dd-mon-yyyy')
--and V.INVOICE_GID(+) = inv.invoice_gid
--and ship_buy.domain_name = 'UPS/CP/VZNB'
and si.shipment_gid(+) = SHIP_BUY.SHIPMENT_GID
AND SI.INVOICE_GID = INV.INVOICE_GID(+)
and SHIP_BUY.INSERT_DATE > '1-JAN-2007'
and SHIP_BUY.USER_DEFINED1_ICON_GID = 'ACCEPTED'
UNION
select distinct corporation_name custer_name,
glog_util.remove_domain(SHIP_BUY.SERVPROV_GID ) SCAC,
glog_util.remove_domain(ship_buy.shipment_gid) buy_shipment_gid,
F_GET_SELL_ID_STRING( SHIP_BUY.SHIPMENT_GID) sell_shipment_gid,
ship_buy.domain_name,
F_GET_ORDER_RELEASE_GID('B',SHIP_BUY.SHIPMENT_GID,0) ORDER_RELEASE_GID,
f_get_refnum_string('SHIPMENT', ship_buy.shipment_gid, 'MBOL_NUMBER_CLEANSED')MBOL_NUMBER,
F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID) POD_RECEIVED_DATE,
f_get_exp_accrue_amt(inv.invoice_gid,'INVOICE') Total_accrual_amount
from shipment ship_buy,
invoice inv,
invoice_shipment si,
-- voucher v,
corporation corp
where corp.domain_name=ship_buy.domain_name
and corp.is_domain_master='Y'
and 1=1
AND ship_buy.domain_name like 'UPS/CP/DFP/%'
and F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID) <= to_char(to_date('31-JUL-2013', 'DD-MON-YYYY'), 'dd-mon-yyyy')
--AND INV.DOMAIN_NAME = 'UPS/CP/VZNB'
--and V.INVOICE_GID(+) = inv.invoice_gid
and si.shipment_gid(+) = SHIP_BUY.SHIPMENT_GID
AND SI.INVOICE_GID = INV.INVOICE_GID(+)
and SHIP_BUY.INSERT_DATE > '1-JAN-2007'
and INV.USER_DEFINED1_ICON_GID = 'ACCEPTED'
GROUP BY corporation_name,SHIP_BUY.SHIPMENT_GID,SHIP_BUY.SERVPROV_GID,ship_buy.domain_name,inv.invoice_gid
ORDER BY CUSTER_NAME, BUY_SHIPMENT_GID;
And I generated the execution plan :
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 3 | 448 | 415 (2)| 00:00:05 |
| 1 | SORT UNIQUE | | 3 | 448 | 414 (87)| 00:00:05 |
| 2 | UNION-ALL | | | | | |
| 3 | NESTED LOOPS OUTER | | 3 | 384 | 57 (0)| 00:00:01 |
|* 4 | HASH JOIN | | 3 | 294 | 54 (0)| 00:00:01 |
|* 5 | TABLE ACCESS BY INDEX ROWID | SHIPMENT | 3 | 195 | 40 (0)| 00:00:01 |
|* 6 | INDEX SKIP SCAN | IND_SHIP_DOM_ICON | 54 | | 25 (0)| 00:00:01 |
|* 7 | TABLE ACCESS FULL | CORPORATION | 4 | 132 | 14 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | IND_INVOICESHIP_SHP_GID | 1 | 30 | 1 (0)| 00:00:01 |
| 9 | HASH GROUP BY | | 1 | 192 | 356 (1)| 00:00:05 |
|* 10 | HASH JOIN | | 1 | 192 | 354 (1)| 00:00:05 |
| 11 | NESTED LOOPS | | | | | |
| 12 | NESTED LOOPS | | 1 | 159 | 339 (0)| 00:00:05 |
| 13 | NESTED LOOPS | | 145 | 13920 | 194 (0)| 00:00:03 |
| 14 | TABLE ACCESS BY INDEX ROWID| INVOICE | 145 | 5220 | 49 (0)| 00:00:01 |
|* 15 | INDEX SKIP SCAN | IDX_INV_TYP_ICON_NAM | 145 | | 17 (0)| 00:00:01 |
|* 16 | INDEX RANGE SCAN | UK_INVOICE_SHIPMENT | 1 | 60 | 1 (0)| 00:00:01 |
|* 17 | INDEX UNIQUE SCAN | PK_SHIPMENT | 1 | | 1 (0)| 00:00:01 |
|* 18 | TABLE ACCESS BY INDEX ROWID | SHIPMENT | 1 | 63 | 1 (0)| 00:00:01 |
|* 19 | TABLE ACCESS FULL | CORPORATION | 4 | 132 | 14 (0)| 00:00:01 |
Predicate Information (identified by operation id):
4 - access("CORP"."DOMAIN_NAME"="SHIP_BUY"."DOMAIN_NAME")
5 - filter("F_GET_POD_RECEIVED_DATE"("SHIP_BUY"."SHIPMENT_GID")<=TO_DATE(' 2013-07-31 00:00:00',
'syyyy-mm-dd hh24:mi:ss') AND "SHIP_BUY"."INSERT_DATE">TO_DATE(' 2007-01-01 00:00:00', 'syyyy-mm-dd
hh24:mi:ss'))
6 - access("SHIP_BUY"."USER_DEFINED1_ICON_GID"='ACCEPTED' AND "SHIP_BUY"."DOMAIN_NAME" LIKE
'UPS/CP/DFP/%')
filter("SHIP_BUY"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%' AND
"SHIP_BUY"."USER_DEFINED1_ICON_GID"='ACCEPTED')
7 - filter("CORP"."IS_DOMAIN_MASTER"='Y' AND "CORP"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%')
8 - access("SI"."SHIPMENT_GID"(+)="SHIP_BUY"."SHIPMENT_GID")
10 - access("CORP"."DOMAIN_NAME"="SHIP_BUY"."DOMAIN_NAME")
15 - access("INV"."USER_DEFINED1_ICON_GID"='ACCEPTED')
filter("INV"."USER_DEFINED1_ICON_GID"='ACCEPTED')
16 - access("SI"."INVOICE_GID"="INV"."INVOICE_GID")
17 - access("SI"."SHIPMENT_GID"="SHIP_BUY"."SHIPMENT_GID")
filter("F_GET_POD_RECEIVED_DATE"("SHIP_BUY"."SHIPMENT_GID")<=TO_DATE(' 2013-07-31 00:00:00',
'syyyy-mm-dd hh24:mi:ss'))
18 - filter("SHIP_BUY"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%' AND "SHIP_BUY"."INSERT_DATE">TO_DATE('
2007-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
19 - filter("CORP"."IS_DOMAIN_MASTER"='Y' AND "CORP"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%')
Statistics
246247 recursive calls
2 db block gets
1660067 consistent gets
13839 physical reads
0 redo size
592054 bytes sent via SQL*Net to client
6024 bytes received via SQL*Net from client
502 SQL*Net roundtrips to/from client
15296 sorts (memory)
0 sorts (disk)
7513 rows processedHmmm...why does this look familiar?
F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID) <= to_char(to_date('31-JUL-2013', 'DD-MON-YYYY'), 'dd-mon-yyyy')
SHIP_BUY.INSERT_DATE > '1-JAN-2007'
Like I said in your other thread about this, these two lines need to be fixed and your function needs to be fixed so the return statement doesn't do an implicit date conversion.
Can't you see what that first line is doing? You're taking a character string, turning it into a date, then back to a character string.
If nothing else, these lines should be...
F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID) <= to_date('31-JUL-2013', 'DD-MON-YYYY')
SHIP_BUY.INSERT_DATE > to_date('01-JAN-2007','DD-MON-YYYY')
(assuming insert_date is a proper date format, fingers crossed) -
Need Help to query Lync Database for User Information
Need Help to Query the lync database to retrieve below user information.
1. SIP Address of the registered user
2. Phone Number configured to the particular account.
3. IP Address
4. Last Logged in time.
I am trying to pull the above information from rtc database for all the registered users. Please let me know if this is possible and it would be great if you can throw some light on what tables to look for the data. Thank You.Hi,
For SIP address and Phone number you can check RTC database.
IP Address:
You can refer to the link below to query IP address:
http://h30499.www3.hp.com/t5/Business-Service-Management-BAC/Monitoring-Lync-with-the-User-Registrations-Viewer-Free-NMC-tool/ba-p/5961497#.UtOU43mIrwo
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
Last Logged in time:
You can refer to the link below:
http://blogs.technet.com/b/dodeitte/archive/2011/05/11/how-to-get-the-last-time-a-user-registered-with-a-front-end.aspx
Best Regards,
Eason Huang
Eason Huang
TechNet Community Support -
Hi,
Looking for your help,
SELECT c.Seq,
case
when s2.Str_Name like 'STR'
then s2.Str_Name
end
as name1,
case
when s2.Str_Name like 'AVE'
then s2.Str_Name
end
as name2
FROM assign a
INNER JOIN customer c on a.seq = c.seq
INNER JOIN address s2 on a.seq = s2.seq
I have a table 'Address' and one field name is Str_Name
and data in this filed can be - STR,AVE,DRI,BLV
when i use the above query -
getting the result with four records like one record for 'STR'(here name2 is blank) and another Record for 'AVE'
(here name1 is blank) and two other records with name1 and name1 both are blank
but, i need only one record as below
seq name1 name2
100 STR AVE
Thanks
Edited by: user13347538 on Jun 30, 2010 9:36 AMBased on test data you provided here is the SQL that will provide you the necessary output ...
SELECT c.Seq,
max( decode( s2.str_name, 'STR', s2.str_name, NULL ) ) as Name1,
max( decode( s2.str_name, 'AVE', s2.str_name, NULL ) ) as Name2,
max( decode( s2.str_name, 'BLV', s2.str_name, NULL ) ) as Name3,
max( decode( s2.str_name, 'DRI', s2.str_name, NULL ) ) as Name4
FROM assign a
INNER JOIN customer c
on a.seq = c.seq
INNER JOIN address s2
on a.seq = s2.seq
GROUP BY c.seq ;
and here is the output ...
SEQ NAME1 NAME2 NAME3 NAME4
100 STR AVE BLV DRI
Tranposing rows into columns is called pivoting. Starting with 11g R2 there is a built-in function available - pivot(). Prior to that release pivoting could be achieved by using DECODE() and aggregate functions.
Here is an useful article by Tom Kyte that explains this concept:
http://www.oracle.com/technology/oramag/oracle/10-jul/o40asktom.html
(refer section - Pivot Query Examples)
Edited by: VishnuR on Jun 30, 2010 7:26 PM -
Help with Query function on EAI Siebel Adapter
Can anyone help?
I have a workflow that uses the Query method on EAI Siebel Adapter to search for a Contact in Siebel. The Root component is Contact and the Child component is Address.
When I pass in a message that contains Contact data (i.e. LastName='Jones') and Address data (City='Perth') to query on, it returns all Contacts that match the Contact data, and for each of those Contacts if the address data matches it also returns the address.
What I want it to do is only return those Contacts that match both the Contact data 'AND' the address data, not all of the Contacts that match the contact data.
I hope this makes sense.
I've also tried using the searchspec function too, but this does not do what I want it to do either.
Hope you can help.
Thanks,
Carl
Can aHi,
can you create a MVG in Contact which will refer to Business Address & then try to use searchspec argument. I hope it will work for you. -
Help in query using regular expression
HI,
I need a help to get the below output using regular expression query. Please help me.
SELECT REGEXP_SUBSTR ('PWRPKG(P/W+P/L+CC)', '[^+]+', 1, lvl) val, lvl
FROM DUAL,(SELECT LEVEL lvl FROM DUAL
CONNECT BY LEVEL <=(SELECT MAX ( LENGTH ('PWRPKG(P/W+P/L+CC)') - LENGTH (REPLACE ('PWRPKG(P/W+P/L+CC)','+',NULL))+ 1) FROM DUAL));
I need the output as
correct result:
==============
val lvl
P/W 1
P/L 2
CC 3
But i tried the above it is not coming the above result. Please help me where i did a mistake.
Thanks in advanceFrank gave you a solution in your other thread. You could simplify it if you are on 11g:
SQL> select * from table_x
2 /
TXT
TECHPKG(INTELLI CC+FRT SONAR)
PWRPKG(P/W+P/L+CC)
select txt,
regexp_substr(
txt,
'(.*\()*([^+)]+)',
1,
column_value,
null,
2
) element,
column_value element_number
from table_x,
table(
cast(
multiset(
select level
from dual
connect by level <= regexp_count(txt,'\+') + 1
as sys.OdciNumberList
order by rowid,
column_value
TXT ELEMENT ELEMENT_NUMBER
TECHPKG(INTELLI CC+FRT SONAR) INTELLI CC 1
TECHPKG(INTELLI CC+FRT SONAR) FRT SONAR 2
PWRPKG(P/W+P/L+CC) P/W 1
PWRPKG(P/W+P/L+CC) P/L 2
PWRPKG(P/W+P/L+CC) CC 3
SQL> SY. -
Help with query to return results from group within table?
Hi
Im a total noob, so please be gentle....!
I am looking at a table that has a WORD column and a WORD_TYPE_ID column.
Words can have the same type_id.
What I am trying to do is write a query that will return the longest word for each word_type_id.
I have been trying for hours to get this and all I seem to get is either error messages or I return the longest word in the whole WORD column.
The furthest I can get before things break down is.....
select word
from table
where
length(word) =
select
max(length(word))
from table
Any help on this or if I could be pointed in the right direction it would be greatly appreciated.
ThanksHi,
Welcome to the forum!
Here's one way:
SELECT word_type_id
, MIN (word) KEEP (DENSE_RANK LAST ORDDER BY LENGTH (word)) AS longest_word
FROM table_x
GROUP BY word_type_id;If there happens to be a tie within some word_type_id (that is, 2 or more words have exactly the same length, which is the longest in that group) the expression above will return the first one, in alphabetic order. (That's what MIN means here.)
Edited by: Frank Kulash on Aug 11, 2009 1:56 PM
You almost had it.
As you noticed, you were getting the longest row in the whole table. That's because your sub-query was looking at the whole table.
If you correlate the sub-query to the row in the main table, as shown below, you can get the longest word in each group:
select word
from table m -- m for main
where length (word) = (
select max (length(word))
from table
where word_type_id = m.word_type_id -- New
); -
Help with query to return last possible value
Can someone please help me create a query for the situation below?
Table: TABLEA
Columns:
FACID VARCHAR2(10),
DEPTID VARCHAR2(10),
CHARGENUMBER NUMBER(10)
I have the following data:
A, B, 1
A, B, 2
C, D, 3
C, D, 4
Would like to return the following:
A, B, 2
C, D, 4
In other words, I would like to return the last possible CHARGENUMBER for FACID and DEPTID.
The table does not have any indexes and it gets loaded from a spreadsheet in that order.
Thanks so much!amazongirl wrote:
Can someone please help me create a query for the situation below?
Table: TABLEA
Columns:
FACID VARCHAR2(10),
DEPTID VARCHAR2(10),
CHARGENUMBER NUMBER(10)
I have the following data:
A, B, 1
A, B, 2
C, D, 3
C, D, 4
Would like to return the following:
A, B, 2
C, D, 4
In other words, I would like to return the last possible CHARGENUMBER for FACID and DEPTID.
The table does not have any indexes and it gets loaded from a spreadsheet in that order.
Thanks so much!Hi girl from amazon,
I hope you give me a note because I answered for a lot of questions and nobody aprecieted that. If you don't me a little point I wil leave this forum because isn't so funny to work for nothing.
You are my last chance to stay here!
FACID DEPTID CHARGENUMBER
A B 1
A B 2
C D 3
C D 4
HR: XE > select x.FACID, x.DEPTID , x.CHARGENUMBER from tableA x,
2 (select DEPTID, FACID, max(CHARGENUMBER) max_val from tableA
3 group by DEPTID, FACID ) y
4 WHERE x.DEPTID = y.DEPTID and
5 x.FACID = y.FACID and
6 x.CHARGENUMBER =max_val;
FACID DEPTID CHARGENUMBER
A B 2
C D 4Regards,
Ion -
Hello, I have the following query that I'm running in Oracle SQL Developer 1.2.1
WITH group_by_4_column_results AS
(SELECT m_atschunk.employee AS employee,
SUM(CASE
WHEN
M_ATSCHUNK.rolloffDaysCount = '108545043' AND m_atschunk.infractiondate BETWEEN SYSDATE - 365 AND SYSDATE THEN 1 ELSE 0 END) as rolloffs,
M_ATSCHUNK.INFRACTIONDATE + 365 as infractionDate
FROM M_ATSCHUNK
group by employee, infractionDate, rolloffDaysCount
SELECT g4.*,
SUM (rolloffs) OVER (PARTITION BY employee) AS total_rolloffs
FROM group_by_4_column_results g4
It will output the key elements of what I need. But where it sums up the 'total_rolloffs', I need to add that number back into the infractiondate column. Any help would be greatly appreciated.
CREATE TABLE M_ATSCHUNK
(EMPLOYEE varchar(50),
ROLLOFFDAYSCOUNT varchar(3),
INFRACTIONDATE date)
INSERT INTO M_ATSCHUNK (EMPLOYEE, ROLLINGOFFDAYSCOUNT, INFRACTIONDATE)
VALUES ('PHIL','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/02 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/03 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/04 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','YES', (to_date('2010/01/05 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','NO', (to_date('2010/02/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('PHIL','NO', (to_date('2010/03/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss')))Phil3061 wrote:
I need to add that number back into the infractiondate column.Well, in general you need to use UPDATE or better MERGE. Howebver, your data sample does not show any rollofs:
SQL> SELECT * FROM M_ATSCHUNK;
EMPLOYEE ROL INFRACTIO
PHIL YES 01-JAN-10
PHIL YES 02-JAN-10
PHIL YES 03-JAN-10
PHIL YES 04-JAN-10
PHIL YES 05-JAN-10
PHIL NO 01-FEB-10
PHIL NO 01-MAR-10
NIKI YES 01-JAN-10
NIKI YES 01-JAN-10
NIKI YES 01-JAN-10
NIKI NO 01-JAN-10
EMPLOYEE ROL INFRACTIO
NIKI NO 01-JAN-10
NIKI NO 01-JAN-10
NIKI NO 01-JAN-10
14 rows selected.
SQL> WITH group_by_4_column_results AS
2 (SELECT m_atschunk.employee AS employee,
3 SUM(CASE
4 WHEN
5 M_ATSCHUNK.rolloffDaysCount = '108545043' AND m_atschunk.infractiondate BETWEEN SYSDATE - 365 AND SYSDATE THEN 1 ELSE 0 END) as
rolloffs,
6 M_ATSCHUNK.INFRACTIONDATE + 365 as infractionDate
7 FROM M_ATSCHUNK
8 group by employee, infractionDate, rolloffDaysCount
9 )
10 SELECT g4.*,
11 SUM (rolloffs) OVER (PARTITION BY employee) AS total_rolloffs
12 FROM group_by_4_column_results g4
13 /
EMPLOYEE ROLLOFFS INFRACTIO TOTAL_ROLLOFFS
NIKI 0 01-JAN-11 0
NIKI 0 01-JAN-11 0
PHIL 0 01-JAN-11 0
PHIL 0 02-JAN-11 0
PHIL 0 03-JAN-11 0
PHIL 0 04-JAN-11 0
PHIL 0 05-JAN-11 0
PHIL 0 01-FEB-11 0
PHIL 0 01-MAR-11 0
9 rows selected.
SQL> So adjust data sample and based on it tell us what are the expected results.
SY. -
Help optimizing query with function
Hello experts,
I need your help optmizing this query which has a condition that matches on results of non-deterministic function. The non-deterministic functino is fedtaxpk.fedtaxpk_pkg.GETFIELDDATAGROUPSEQKEY. Values that it returns depends on contents of a table, so I can't really create a function index.
Any input will be appreciated. Thanks in advance!
Sorry I couln't format the query plan properly. Can somebody advise how? Thanks again!
Giovanni
explain plan for
WITH tg AS
(SELECT taxgroup_code FROM taxgroup
WHERE taxgroup_code = 'TAXGROUP2' --?
AND taxgroup_delete_ind = 'N' AND taxgroup_active_ind = 'A'),
le_hb AS
(SELECT tgi.taxgroup_code, tgi.legalentity_id, tgi.hyperionbase_id, ou.orgunit_code, ou.hyperionbase_code
FROM tg, taxgroupitem tgi, orgunit_vw ou
WHERE tg.taxgroup_code = tgi.taxgroup_code
AND tgi.legalentity_id = ou.legalentity_id AND tgi.hyperionbase_id = ou.hyperionbase_id
UNION
SELECT tgi.taxgroup_code, tgi.legalentity_id, ou.hyperionbase_id, ou.orgunit_code, ou.hyperionbase_code
FROM tg, taxgroupitem tgi, orgunit_vw ou
WHERE tg.taxgroup_code = tgi.taxgroup_code
AND tgi.legalentity_id = ou.legalentity_id AND tgi.hyperionbase_id IS NULL),
au AS
(SELECT appusage_code FROM appusage WHERE appusage_code = 'CONSOLIDATION'),
prs AS
(SELECT prs_key,
(CASE WHEN instr(prs_key, ':') = 0 THEN prs_key
ELSE SUBSTR(prs_key, 1, (instr(prs_key, ':')-1) ) END) first_val
FROM
(SELECT fedtaxpk.fedtaxpk_pkg.GETFIELDDATAGROUPSEQKEY(164415 --?
) prs_key
FROM dual
grs AS
(SELECT prs.*, fd.fielddata_group_sequence fd_grpseq
FROM prs, fielddata fd, le_hb
WHERE prs.first_val = fd.fielddata_value
AND le_hb.legalentity_id = fd.legalentity_id
AND le_hb.hyperionbase_id = fd.hyperionbase_id),
fdk AS
(SELECT
cd.celldef_id, fedtaxpk.fedtaxpk_pkg.GETFIELDDATAGROUPSEQKEY(fd.fielddata_group_sequence) fd_key,
fd.fielddata_value fd_val, fd.fielddata_group_sequence fd_grpseq,
ROW_NUMBER() OVER (PARTITION BY cd.celldef_id, fedtaxpk.fedtaxpk_pkg.GETFIELDDATAGROUPSEQKEY(fd.fielddata_group_sequence)
ORDER BY fd.fielddata_group_sequence) rn,
grs.prs_key
FROM le_hb, grs, fielddata fd, tablecell tc, celldef cd, tabledef td, appusage au
WHERE le_hb.legalentity_id = fd.legalentity_id AND le_hb.hyperionbase_id = fd.hyperionbase_id
AND fd.fielddata_id = tc.fielddata_id AND tc.celldef_id = cd.celldef_id
AND cd.tabledef_id = td.tabledef_id
AND grs.fd_grpseq = fd.fielddata_parent_row_sequence
and grs.prs_key = fedtaxpk.fedtaxpk_pkg.GETFIELDDATAGROUPSEQKEY(fd.fielddata_parent_row_sequence)
AND cd.celldef_key_ind = 'Y'
AND fd.fielddata_delete_ind = 'N'
AND td.tabledef_id = 2265
fda AS
(SELECT
cd.celldef_id, fedtaxpk.fedtaxpk_pkg.GETFIELDDATAGROUPSEQKEY(fd.fielddata_group_sequence) fd_key,
TO_CHAR(TO_NUMBER(SUM(fd.fielddata_value))) fd_val,
MIN(fd.fielddata_group_sequence) fd_grpseq,
grs.prs_key
FROM le_hb, grs, fielddata fd, tablecell tc, celldef cd, tabledef td
WHERE le_hb.legalentity_id = fd.legalentity_id AND le_hb.hyperionbase_id = fd.hyperionbase_id
AND fd.fielddata_id = tc.fielddata_id AND tc.celldef_id = cd.celldef_id
AND cd.tabledef_id = td.tabledef_id
AND grs.fd_grpseq = fd.fielddata_parent_row_sequence
and grs.prs_key = fedtaxpk.fedtaxpk_pkg.GETFIELDDATAGROUPSEQKEY(fd.fielddata_parent_row_sequence)
AND cd.celldef_adjustable_ind = 'Y'
AND fd.fielddata_delete_ind = 'N'
AND td.tabledef_id = 2265
GROUP BY cd.celldef_id, fedtaxpk.fedtaxpk_pkg.GETFIELDDATAGROUPSEQKEY(fd.fielddata_group_sequence),
grs.prs_key
SELECT NULL LEGALENTITY_ID, NULL hyperionbase_id, fdk.celldef_id, TO_CHAR(NULL) role_code, NULL userinfo_id, cd.celldef_adjustable_ind,
'N' celldef_editable_ind, cd.celldef_filter_code, cd.celldef_validate_rule, cd.celldef_list_code,
cd.celldef_longstring_ind, aua.appusageaccess_visible_ind celldef_viewable_ind,
cd.celldef_column_sequence, cd.celldef_column_label,
cd.celldef_column_sort_order, NULL tablecell_id, fdk.fd_grpseq tablecell_row_sequence, NULL tablecell_row_label,
'N' tablecell_delete_ind, NULL tablecell_create_by, TO_DATE(NULL) tablecell_create_dt, TO_CHAR(NULL) tablecell_update_by,
TO_DATE(NULL) tablecell_update_dt, NULL fielddata_id, TO_CHAR(NULL) datatype_code, NULL fielddata_adjref_id,
fdk.fd_grpseq fielddata_group_sequence, NULL fielddata_parent_row_sequence, NULL lookup_id,
fdk.fd_val fielddata_value, 'N' fielddata_delete_ind, TO_CHAR(NULL) fielddata_create_by,
TO_DATE(NULL) fielddata_create_dt, TO_CHAR(NULL) fielddata_update_by, TO_DATE(NULL) fielddata_update_dt,
fdk.fd_key
FROM fdk, celldef cd, appusageaccess aua, au
WHERE fdk.celldef_id = cd.celldef_id
AND cd.celldef_id = aua.celldef_id
AND aua.appusage_code = au.appusage_code
AND fdk.rn = 1
UNION ALL
SELECT NULL LEGALENTITY_ID, NULL hyperionbase_id, fda.celldef_id, TO_CHAR(NULL) role_code, NULL userinfo_id, cd.celldef_adjustable_ind,
'N' celldef_editable_ind, cd.celldef_filter_code, cd.celldef_validate_rule, cd.celldef_list_code,
cd.celldef_longstring_ind, aua.appusageaccess_visible_ind celldef_viewable_ind,
cd.celldef_column_sequence, cd.celldef_column_label,
cd.celldef_column_sort_order, NULL tablecell_id, fda.fd_grpseq tablecell_row_sequence, NULL tablecell_row_label,
'N' tablecell_delete_ind, NULL tablecell_create_by, TO_DATE(NULL) tablecell_create_dt, TO_CHAR(NULL) tablecell_update_by,
TO_DATE(NULL) tablecell_update_dt, NULL fielddata_id, TO_CHAR(NULL) datatype_code, NULL fielddata_adjref_id,
fda.fd_grpseq fielddata_group_sequence, NULL fielddata_parent_row_sequence, NULL lookup_id,
fda.fd_val fielddata_value, 'N' fielddata_delete_ind, TO_CHAR(NULL) fielddata_create_by,
TO_DATE(NULL) fielddata_create_dt, TO_CHAR(NULL) fielddata_update_by, TO_DATE(NULL) fielddata_update_dt,
fda.fd_key
FROM fda, celldef cd, appusageaccess aua, au
WHERE fda.celldef_id = cd.celldef_id
AND cd.celldef_id = aua.celldef_id
AND aua.appusage_code = au.appusage_code
ORDER BY fielddata_group_sequence, celldef_column_sequence
Query Plan:
Plan hash value: 522363234
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 2 | 6227 | 249 (2)| 00:00:03 |
| 1 | TEMP TABLE TRANSFORMATION | | | | | |
| 2 | LOAD AS SELECT | | | | | |
|* 3 | TABLE ACCESS BY INDEX ROWID | TAXGROUP | 1 | 14 | 1 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | PK_TAXGROUP | 1 | | 0 (0)| 00:00:01 |
| 5 | LOAD AS SELECT | | | | | |
| 6 | SORT UNIQUE | | 4 | 224 | 12 (59)| 00:00:01 |
| 7 | UNION-ALL | | | | | |
| 8 | TABLE ACCESS BY INDEX ROWID | ORGUNIT | 1 | 29 | 2 (0)| 00:00:01 |
| 9 | NESTED LOOPS | | 1 | 56 | 5 (0)| 00:00:01 |
| 10 | NESTED LOOPS | | 1 | 27 | 3 (0)| 00:00:01 |
| 11 | VIEW | | 1 | 10 | 2 (0)| 00:00:01 |
| 12 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B51_2EBE182 | 1 | 10 | 2 (0)| 00:00:01 |
|* 13 | TABLE ACCESS BY INDEX ROWID | TAXGROUPITEM | 1 | 17 | 1 (0)| 00:00:01 |
|* 14 | INDEX RANGE SCAN | XF1_TAXGROUPITEM_TAXGROUP | 1 | | 0 (0)| 00:00:01 |
|* 15 | INDEX RANGE SCAN | XF1_ORGUNIT_ID | 1 | | 1 (0)| 00:00:01 |
| 16 | TABLE ACCESS BY INDEX ROWID | ORGUNIT | 3 | 87 | 2 (0)| 00:00:01 |
| 17 | NESTED LOOPS | | 3 | 168 | 5 (0)| 00:00:01 |
| 18 | NESTED LOOPS | | 1 | 27 | 3 (0)| 00:00:01 |
| 19 | VIEW | | 1 | 10 | 2 (0)| 00:00:01 |
| 20 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B51_2EBE182 | 1 | 10 | 2 (0)| 00:00:01 |
|* 21 | TABLE ACCESS BY INDEX ROWID | TAXGROUPITEM | 1 | 17 | 1 (0)| 00:00:01 |
|* 22 | INDEX RANGE SCAN | XF1_TAXGROUPITEM_TAXGROUP | 1 | | 0 (0)| 00:00:01 |
|* 23 | INDEX RANGE SCAN | XF1_ORGUNIT_ID | 3 | | 1 (0)| 00:00:01 |
| 24 | LOAD AS SELECT | | | | | |
|* 25 | INDEX UNIQUE SCAN | PK_APPUSAGE | 1 | 10 | 0 (0)| 00:00:01 |
| 26 | LOAD AS SELECT | | | | | |
|* 27 | TABLE ACCESS BY INDEX ROWID | FIELDDATA | 7 | 147 | 28 (0)| 00:00:01 |
| 28 | NESTED LOOPS | | 27 | 1269 | 117 (1)| 00:00:02 |
| 29 | NESTED LOOPS | | 4 | 104 | 4 (0)| 00:00:01 |
| 30 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 31 | VIEW | | 4 | 104 | 2 (0)| 00:00:01 |
| 32 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B52_2EBE182 | 4 | 388 | 2 (0)| 00:00:01 |
|* 33 | INDEX RANGE SCAN | XF11_DATA_LE_HB | 117 | | 12 (0)| 00:00:01 |
| 34 | SORT ORDER BY | | 2 | 6227 | 248 (51)| 00:00:03 |
| 35 | UNION-ALL | | | | | |
| 36 | NESTED LOOPS | | 1 | 4110 | 125 (2)| 00:00:02 |
| 37 | MERGE JOIN CARTESIAN | | 1 | 4093 | 124 (2)| 00:00:02 |
| 38 | NESTED LOOPS | | 1 | 4076 | 122 (2)| 00:00:02 |
|* 39 | VIEW | | 1 | 4043 | 121 (2)| 00:00:02 |
|* 40 | WINDOW SORT PUSHED RANK | | 1 | 2099 | 121 (2)| 00:00:02 |
| 41 | MERGE JOIN CARTESIAN | | 1 | 2099 | 120 (1)| 00:00:02 |
| 42 | NESTED LOOPS | | 1 | 2099 | 119 (1)| 00:00:02 |
| 43 | NESTED LOOPS | | 1 | 2088 | 118 (1)| 00:00:02 |
|* 44 | HASH JOIN | | 1 | 2077 | 117 (1)| 00:00:02 |
|* 45 | TABLE ACCESS BY INDEX ROWID| FIELDDATA | 117 | 3744 | 28 (0)| 00:00:01 |
| 46 | NESTED LOOPS | | 466 | 28892 | 114 (0)| 00:00:02 |
| 47 | NESTED LOOPS | | 4 | 120 | 2 (0)| 00:00:01 |
|* 48 | INDEX UNIQUE SCAN | PK_TABLEDEF | 1 | 4 | 0 (0)| 00:00:01 |
| 49 | VIEW | | 4 | 104 | 2 (0)| 00:00:01 |
| 50 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B52_2EBE182 | 4 | 388 | 2 (0)| 00:00:01 |
|* 51 | INDEX RANGE SCAN | XF11_DATA_LE_HB | 117 | | 12 (0)| 00:00:01 |
| 52 | VIEW | | 27 | 54405 | 2 (0)| 00:00:01 |
| 53 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B54_2EBE182 | 27 | 1269 | 2 (0)| 00:00:01 |
| 54 | TABLE ACCESS BY INDEX ROWID | TABLECELL | 1 | 11 | 1 (0)| 00:00:01 |
|* 55 | INDEX UNIQUE SCAN | XF1_TBLCEL_DATA | 1 | | 0 (0)| 00:00:01 |
|* 56 | TABLE ACCESS BY INDEX ROWID | CELLDEF | 1 | 11 | 1 (0)| 00:00:01 |
|* 57 | INDEX UNIQUE SCAN | PK_CELLDEF | 1 | | 0 (0)| 00:00:01 |
| 58 | BUFFER SORT | | 5 | | 120 (2)| 00:00:02 |
| 59 | INDEX FULL SCAN | PK_APPUSAGE | 5 | | 1 (0)| 00:00:01 |
| 60 | TABLE ACCESS BY INDEX ROWID | CELLDEF | 1 | 33 | 1 (0)| 00:00:01 |
|* 61 | INDEX UNIQUE SCAN | PK_CELLDEF | 1 | | 0 (0)| 00:00:01 |
| 62 | BUFFER SORT | | 1 | 17 | 123 (2)| 00:00:02 |
| 63 | VIEW | | 1 | 17 | 2 (0)| 00:00:01 |
| 64 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B53_2EBE182 | 1 | 10 | 2 (0)| 00:00:01 |
| 65 | TABLE ACCESS BY INDEX ROWID | APPUSAGEACCESS | 1 | 17 | 1 (0)| 00:00:01 |
|* 66 | INDEX UNIQUE SCAN | AK_APPUSAGEACCESS | 1 | | 0 (0)| 00:00:01 |
| 67 | NESTED LOOPS | | 1 | 2117 | 124 (2)| 00:00:02 |
| 68 | MERGE JOIN CARTESIAN | | 1 | 2100 | 123 (2)| 00:00:02 |
| 69 | NESTED LOOPS | | 1 | 2083 | 121 (2)| 00:00:02 |
| 70 | VIEW | | 1 | 2050 | 120 (2)| 00:00:02 |
| 71 | HASH GROUP BY | | 1 | 2091 | 120 (2)| 00:00:02 |
| 72 | NESTED LOOPS | | 1 | 2091 | 119 (1)| 00:00:02 |
| 73 | NESTED LOOPS | | 1 | 2080 | 118 (1)| 00:00:02 |
|* 74 | HASH JOIN | | 1 | 2069 | 117 (1)| 00:00:02 |
|* 75 | TABLE ACCESS BY INDEX ROWID | FIELDDATA | 117 | 3744 | 28 (0)| 00:00:01 |
| 76 | NESTED LOOPS | | 466 | 28892 | 114 (0)| 00:00:02 |
| 77 | NESTED LOOPS | | 4 | 120 | 2 (0)| 00:00:01 |
|* 78 | INDEX UNIQUE SCAN | PK_TABLEDEF | 1 | 4 | 0 (0)| 00:00:01 |
| 79 | VIEW | | 4 | 104 | 2 (0)| 00:00:01 |
| 80 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B52_2EBE182 | 4 | 388 | 2 (0)| 00:00:01 |
|* 81 | INDEX RANGE SCAN | XF11_DATA_LE_HB | 117 | | 12 (0)| 00:00:01 |
| 82 | VIEW | | 27 | 54189 | 2 (0)| 00:00:01 |
| 83 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B54_2EBE182 | 27 | 1269 | 2 (0)| 00:00:01 |
| 84 | TABLE ACCESS BY INDEX ROWID | TABLECELL | 1 | 11 | 1 (0)| 00:00:01 |
|* 85 | INDEX UNIQUE SCAN | XF1_TBLCEL_DATA | 1 | | 0 (0)| 00:00:01 |
|* 86 | TABLE ACCESS BY INDEX ROWID | CELLDEF | 1 | 11 | 1 (0)| 00:00:01 |
|* 87 | INDEX UNIQUE SCAN | PK_CELLDEF | 1 | | 0 (0)| 00:00:01 |
| 88 | TABLE ACCESS BY INDEX ROWID | CELLDEF | 1 | 33 | 1 (0)| 00:00:01 |
|* 89 | INDEX UNIQUE SCAN | PK_CELLDEF | 1 | | 0 (0)| 00:00:01 |
| 90 | BUFFER SORT | | 1 | 17 | 122 (2)| 00:00:02 |
| 91 | VIEW | | 1 | 17 | 2 (0)| 00:00:01 |
| 92 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B53_2EBE182 | 1 | 10 | 2 (0)| 00:00:01 |
| 93 | TABLE ACCESS BY INDEX ROWID | APPUSAGEACCESS | 1 | 17 | 1 (0)| 00:00:01 |
|* 94 | INDEX UNIQUE SCAN | AK_APPUSAGEACCESS | 1 | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - filter("TAXGROUP_DELETE_IND"='N' AND "TAXGROUP_ACTIVE_IND"='A')
4 - access("TAXGROUP_CODE"='TAXGROUP2')
13 - filter("TGI"."HYPERIONBASE_ID" IS NOT NULL)
14 - access("TG"."TAXGROUP_CODE"="TGI"."TAXGROUP_CODE")
15 - access("TGI"."LEGALENTITY_ID"="OU"."ORGUNIT_ID" AND "TGI"."HYPERIONBASE_ID"="OU"."HYPERIONBASE_ID")
21 - filter("TGI"."HYPERIONBASE_ID" IS NULL)
22 - access("TG"."TAXGROUP_CODE"="TGI"."TAXGROUP_CODE")
23 - access("TGI"."LEGALENTITY_ID"="OU"."ORGUNIT_ID")
25 - access("APPUSAGE_CODE"='CONSOLIDATION')
27 - filter("FD"."FIELDDATA_VALUE"=CASE INSTR("FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"(164415),':') WHEN 0
THEN "FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"(164415) ELSE
SUBSTR("FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"(164415),1,INSTR("FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"(16441
5),':')-1) END )
33 - access("LE_HB"."LEGALENTITY_ID"="FD"."LEGALENTITY_ID" AND
"LE_HB"."HYPERIONBASE_ID"="FD"."HYPERIONBASE_ID")
39 - filter("FDK"."RN"=1)
40 - filter(ROW_NUMBER() OVER ( PARTITION BY "CD"."CELLDEF_ID","FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"("FD"
."FIELDDATA_GROUP_SEQUENCE") ORDER BY "FD"."FIELDDATA_GROUP_SEQUENCE")<=1)
44 - access("GRS"."FD_GRPSEQ"="FD"."FIELDDATA_PARENT_ROW_SEQUENCE" AND
"GRS"."PRS_KEY"="FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"("FD"."FIELDDATA_PARENT_ROW_SEQUENCE"))
45 - filter("FD"."FIELDDATA_DELETE_IND"='N')
48 - access("TD"."TABLEDEF_ID"=2265)
51 - access("LE_HB"."LEGALENTITY_ID"="FD"."LEGALENTITY_ID" AND
"LE_HB"."HYPERIONBASE_ID"="FD"."HYPERIONBASE_ID")
55 - access("FD"."FIELDDATA_ID"="TC"."FIELDDATA_ID")
56 - filter("CD"."TABLEDEF_ID"=2265 AND "CD"."CELLDEF_KEY_IND"='Y')
57 - access("TC"."CELLDEF_ID"="CD"."CELLDEF_ID")
61 - access("FDK"."CELLDEF_ID"="CD"."CELLDEF_ID")
66 - access("AUA"."APPUSAGE_CODE"="AU"."APPUSAGE_CODE" AND "CD"."CELLDEF_ID"="AUA"."CELLDEF_ID")
74 - access("GRS"."FD_GRPSEQ"="FD"."FIELDDATA_PARENT_ROW_SEQUENCE" AND
"GRS"."PRS_KEY"="FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"("FD"."FIELDDATA_PARENT_ROW_SEQUENCE"))
75 - filter("FD"."FIELDDATA_DELETE_IND"='N')
78 - access("TD"."TABLEDEF_ID"=2265)
81 - access("LE_HB"."LEGALENTITY_ID"="FD"."LEGALENTITY_ID" AND
"LE_HB"."HYPERIONBASE_ID"="FD"."HYPERIONBASE_ID")
85 - access("FD"."FIELDDATA_ID"="TC"."FIELDDATA_ID")
86 - filter("CD"."TABLEDEF_ID"=2265 AND "CD"."CELLDEF_ADJUSTABLE_IND"='Y')
87 - access("TC"."CELLDEF_ID"="CD"."CELLDEF_ID")
89 - access("FDA"."CELLDEF_ID"="CD"."CELLDEF_ID")
94 - access("AUA"."APPUSAGE_CODE"="AU"."APPUSAGE_CODE" AND "CD"."CELLDEF_ID"="AUA"."CELLDEF_ID")Thanks cd.
Here's the query plan:
Query Plan:
Plan hash value: 522363234
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 2 | 6227 | 249 (2)| 00:00:03 |
| 1 | TEMP TABLE TRANSFORMATION | | | | | |
| 2 | LOAD AS SELECT | | | | | |
|* 3 | TABLE ACCESS BY INDEX ROWID | TAXGROUP | 1 | 14 | 1 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | PK_TAXGROUP | 1 | | 0 (0)| 00:00:01 |
| 5 | LOAD AS SELECT | | | | | |
| 6 | SORT UNIQUE | | 4 | 224 | 12 (59)| 00:00:01 |
| 7 | UNION-ALL | | | | | |
| 8 | TABLE ACCESS BY INDEX ROWID | ORGUNIT | 1 | 29 | 2 (0)| 00:00:01 |
| 9 | NESTED LOOPS | | 1 | 56 | 5 (0)| 00:00:01 |
| 10 | NESTED LOOPS | | 1 | 27 | 3 (0)| 00:00:01 |
| 11 | VIEW | | 1 | 10 | 2 (0)| 00:00:01 |
| 12 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B51_2EBE182 | 1 | 10 | 2 (0)| 00:00:01 |
|* 13 | TABLE ACCESS BY INDEX ROWID | TAXGROUPITEM | 1 | 17 | 1 (0)| 00:00:01 |
|* 14 | INDEX RANGE SCAN | XF1_TAXGROUPITEM_TAXGROUP | 1 | | 0 (0)| 00:00:01 |
|* 15 | INDEX RANGE SCAN | XF1_ORGUNIT_ID | 1 | | 1 (0)| 00:00:01 |
| 16 | TABLE ACCESS BY INDEX ROWID | ORGUNIT | 3 | 87 | 2 (0)| 00:00:01 |
| 17 | NESTED LOOPS | | 3 | 168 | 5 (0)| 00:00:01 |
| 18 | NESTED LOOPS | | 1 | 27 | 3 (0)| 00:00:01 |
| 19 | VIEW | | 1 | 10 | 2 (0)| 00:00:01 |
| 20 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B51_2EBE182 | 1 | 10 | 2 (0)| 00:00:01 |
|* 21 | TABLE ACCESS BY INDEX ROWID | TAXGROUPITEM | 1 | 17 | 1 (0)| 00:00:01 |
|* 22 | INDEX RANGE SCAN | XF1_TAXGROUPITEM_TAXGROUP | 1 | | 0 (0)| 00:00:01 |
|* 23 | INDEX RANGE SCAN | XF1_ORGUNIT_ID | 3 | | 1 (0)| 00:00:01 |
| 24 | LOAD AS SELECT | | | | | |
|* 25 | INDEX UNIQUE SCAN | PK_APPUSAGE | 1 | 10 | 0 (0)| 00:00:01 |
| 26 | LOAD AS SELECT | | | | | |
|* 27 | TABLE ACCESS BY INDEX ROWID | FIELDDATA | 7 | 147 | 28 (0)| 00:00:01 |
| 28 | NESTED LOOPS | | 27 | 1269 | 117 (1)| 00:00:02 |
| 29 | NESTED LOOPS | | 4 | 104 | 4 (0)| 00:00:01 |
| 30 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 31 | VIEW | | 4 | 104 | 2 (0)| 00:00:01 |
| 32 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B52_2EBE182 | 4 | 388 | 2 (0)| 00:00:01 |
|* 33 | INDEX RANGE SCAN | XF11_DATA_LE_HB | 117 | | 12 (0)| 00:00:01 |
| 34 | SORT ORDER BY | | 2 | 6227 | 248 (51)| 00:00:03 |
| 35 | UNION-ALL | | | | | |
| 36 | NESTED LOOPS | | 1 | 4110 | 125 (2)| 00:00:02 |
| 37 | MERGE JOIN CARTESIAN | | 1 | 4093 | 124 (2)| 00:00:02 |
| 38 | NESTED LOOPS | | 1 | 4076 | 122 (2)| 00:00:02 |
|* 39 | VIEW | | 1 | 4043 | 121 (2)| 00:00:02 |
|* 40 | WINDOW SORT PUSHED RANK | | 1 | 2099 | 121 (2)| 00:00:02 |
| 41 | MERGE JOIN CARTESIAN | | 1 | 2099 | 120 (1)| 00:00:02 |
| 42 | NESTED LOOPS | | 1 | 2099 | 119 (1)| 00:00:02 |
| 43 | NESTED LOOPS | | 1 | 2088 | 118 (1)| 00:00:02 |
|* 44 | HASH JOIN | | 1 | 2077 | 117 (1)| 00:00:02 |
|* 45 | TABLE ACCESS BY INDEX ROWID| FIELDDATA | 117 | 3744 | 28 (0)| 00:00:01 |
| 46 | NESTED LOOPS | | 466 | 28892 | 114 (0)| 00:00:02 |
| 47 | NESTED LOOPS | | 4 | 120 | 2 (0)| 00:00:01 |
|* 48 | INDEX UNIQUE SCAN | PK_TABLEDEF | 1 | 4 | 0 (0)| 00:00:01 |
| 49 | VIEW | | 4 | 104 | 2 (0)| 00:00:01 |
| 50 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B52_2EBE182 | 4 | 388 | 2 (0)| 00:00:01 |
|* 51 | INDEX RANGE SCAN | XF11_DATA_LE_HB | 117 | | 12 (0)| 00:00:01 |
| 52 | VIEW | | 27 | 54405 | 2 (0)| 00:00:01 |
| 53 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B54_2EBE182 | 27 | 1269 | 2 (0)| 00:00:01 |
| 54 | TABLE ACCESS BY INDEX ROWID | TABLECELL | 1 | 11 | 1 (0)| 00:00:01 |
|* 55 | INDEX UNIQUE SCAN | XF1_TBLCEL_DATA | 1 | | 0 (0)| 00:00:01 |
|* 56 | TABLE ACCESS BY INDEX ROWID | CELLDEF | 1 | 11 | 1 (0)| 00:00:01 |
|* 57 | INDEX UNIQUE SCAN | PK_CELLDEF | 1 | | 0 (0)| 00:00:01 |
| 58 | BUFFER SORT | | 5 | | 120 (2)| 00:00:02 |
| 59 | INDEX FULL SCAN | PK_APPUSAGE | 5 | | 1 (0)| 00:00:01 |
| 60 | TABLE ACCESS BY INDEX ROWID | CELLDEF | 1 | 33 | 1 (0)| 00:00:01 |
|* 61 | INDEX UNIQUE SCAN | PK_CELLDEF | 1 | | 0 (0)| 00:00:01 |
| 62 | BUFFER SORT | | 1 | 17 | 123 (2)| 00:00:02 |
| 63 | VIEW | | 1 | 17 | 2 (0)| 00:00:01 |
| 64 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B53_2EBE182 | 1 | 10 | 2 (0)| 00:00:01 |
| 65 | TABLE ACCESS BY INDEX ROWID | APPUSAGEACCESS | 1 | 17 | 1 (0)| 00:00:01 |
|* 66 | INDEX UNIQUE SCAN | AK_APPUSAGEACCESS | 1 | | 0 (0)| 00:00:01 |
| 67 | NESTED LOOPS | | 1 | 2117 | 124 (2)| 00:00:02 |
| 68 | MERGE JOIN CARTESIAN | | 1 | 2100 | 123 (2)| 00:00:02 |
| 69 | NESTED LOOPS | | 1 | 2083 | 121 (2)| 00:00:02 |
| 70 | VIEW | | 1 | 2050 | 120 (2)| 00:00:02 |
| 71 | HASH GROUP BY | | 1 | 2091 | 120 (2)| 00:00:02 |
| 72 | NESTED LOOPS | | 1 | 2091 | 119 (1)| 00:00:02 |
| 73 | NESTED LOOPS | | 1 | 2080 | 118 (1)| 00:00:02 |
|* 74 | HASH JOIN | | 1 | 2069 | 117 (1)| 00:00:02 |
|* 75 | TABLE ACCESS BY INDEX ROWID | FIELDDATA | 117 | 3744 | 28 (0)| 00:00:01 |
| 76 | NESTED LOOPS | | 466 | 28892 | 114 (0)| 00:00:02 |
| 77 | NESTED LOOPS | | 4 | 120 | 2 (0)| 00:00:01 |
|* 78 | INDEX UNIQUE SCAN | PK_TABLEDEF | 1 | 4 | 0 (0)| 00:00:01 |
| 79 | VIEW | | 4 | 104 | 2 (0)| 00:00:01 |
| 80 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B52_2EBE182 | 4 | 388 | 2 (0)| 00:00:01 |
|* 81 | INDEX RANGE SCAN | XF11_DATA_LE_HB | 117 | | 12 (0)| 00:00:01 |
| 82 | VIEW | | 27 | 54189 | 2 (0)| 00:00:01 |
| 83 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B54_2EBE182 | 27 | 1269 | 2 (0)| 00:00:01 |
| 84 | TABLE ACCESS BY INDEX ROWID | TABLECELL | 1 | 11 | 1 (0)| 00:00:01 |
|* 85 | INDEX UNIQUE SCAN | XF1_TBLCEL_DATA | 1 | | 0 (0)| 00:00:01 |
|* 86 | TABLE ACCESS BY INDEX ROWID | CELLDEF | 1 | 11 | 1 (0)| 00:00:01 |
|* 87 | INDEX UNIQUE SCAN | PK_CELLDEF | 1 | | 0 (0)| 00:00:01 |
| 88 | TABLE ACCESS BY INDEX ROWID | CELLDEF | 1 | 33 | 1 (0)| 00:00:01 |
|* 89 | INDEX UNIQUE SCAN | PK_CELLDEF | 1 | | 0 (0)| 00:00:01 |
| 90 | BUFFER SORT | | 1 | 17 | 122 (2)| 00:00:02 |
| 91 | VIEW | | 1 | 17 | 2 (0)| 00:00:01 |
| 92 | TABLE ACCESS FULL | SYS_TEMP_0FD9D9B53_2EBE182 | 1 | 10 | 2 (0)| 00:00:01 |
| 93 | TABLE ACCESS BY INDEX ROWID | APPUSAGEACCESS | 1 | 17 | 1 (0)| 00:00:01 |
|* 94 | INDEX UNIQUE SCAN | AK_APPUSAGEACCESS | 1 | | 0 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
3 - filter("TAXGROUP_DELETE_IND"='N' AND "TAXGROUP_ACTIVE_IND"='A')
4 - access("TAXGROUP_CODE"='TAXGROUP2')
13 - filter("TGI"."HYPERIONBASE_ID" IS NOT NULL)
14 - access("TG"."TAXGROUP_CODE"="TGI"."TAXGROUP_CODE")
15 - access("TGI"."LEGALENTITY_ID"="OU"."ORGUNIT_ID" AND "TGI"."HYPERIONBASE_ID"="OU"."HYPERIONBASE_ID")
21 - filter("TGI"."HYPERIONBASE_ID" IS NULL)
22 - access("TG"."TAXGROUP_CODE"="TGI"."TAXGROUP_CODE")
23 - access("TGI"."LEGALENTITY_ID"="OU"."ORGUNIT_ID")
25 - access("APPUSAGE_CODE"='CONSOLIDATION')
27 - filter("FD"."FIELDDATA_VALUE"=CASE INSTR("FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"(164415),':') WHEN 0
THEN "FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"(164415) ELSE
SUBSTR("FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"(164415),1,INSTR("FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"(16441
5),':')-1) END )
33 - access("LE_HB"."LEGALENTITY_ID"="FD"."LEGALENTITY_ID" AND
"LE_HB"."HYPERIONBASE_ID"="FD"."HYPERIONBASE_ID")
39 - filter("FDK"."RN"=1)
40 - filter(ROW_NUMBER() OVER ( PARTITION BY "CD"."CELLDEF_ID","FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"("FD"
."FIELDDATA_GROUP_SEQUENCE") ORDER BY "FD"."FIELDDATA_GROUP_SEQUENCE")<=1)
44 - access("GRS"."FD_GRPSEQ"="FD"."FIELDDATA_PARENT_ROW_SEQUENCE" AND
"GRS"."PRS_KEY"="FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"("FD"."FIELDDATA_PARENT_ROW_SEQUENCE"))
45 - filter("FD"."FIELDDATA_DELETE_IND"='N')
48 - access("TD"."TABLEDEF_ID"=2265)
51 - access("LE_HB"."LEGALENTITY_ID"="FD"."LEGALENTITY_ID" AND
"LE_HB"."HYPERIONBASE_ID"="FD"."HYPERIONBASE_ID")
55 - access("FD"."FIELDDATA_ID"="TC"."FIELDDATA_ID")
56 - filter("CD"."TABLEDEF_ID"=2265 AND "CD"."CELLDEF_KEY_IND"='Y')
57 - access("TC"."CELLDEF_ID"="CD"."CELLDEF_ID")
61 - access("FDK"."CELLDEF_ID"="CD"."CELLDEF_ID")
66 - access("AUA"."APPUSAGE_CODE"="AU"."APPUSAGE_CODE" AND "CD"."CELLDEF_ID"="AUA"."CELLDEF_ID")
74 - access("GRS"."FD_GRPSEQ"="FD"."FIELDDATA_PARENT_ROW_SEQUENCE" AND
"GRS"."PRS_KEY"="FEDTAXPK_PKG"."GETFIELDDATAGROUPSEQKEY"("FD"."FIELDDATA_PARENT_ROW_SEQUENCE"))
75 - filter("FD"."FIELDDATA_DELETE_IND"='N')
78 - access("TD"."TABLEDEF_ID"=2265)
81 - access("LE_HB"."LEGALENTITY_ID"="FD"."LEGALENTITY_ID" AND
"LE_HB"."HYPERIONBASE_ID"="FD"."HYPERIONBASE_ID")
85 - access("FD"."FIELDDATA_ID"="TC"."FIELDDATA_ID")
86 - filter("CD"."TABLEDEF_ID"=2265 AND "CD"."CELLDEF_ADJUSTABLE_IND"='Y')
87 - access("TC"."CELLDEF_ID"="CD"."CELLDEF_ID")
89 - access("FDA"."CELLDEF_ID"="CD"."CELLDEF_ID")
94 - access("AUA"."APPUSAGE_CODE"="AU"."APPUSAGE_CODE" AND "CD"."CELLDEF_ID"="AUA"."CELLDEF_ID") -
Need help with query that can look data back please help.
hi guys i have a table like such
CREATE TABLE "FGL"
"FGL_GRNT_CODE" VARCHAR2(60),
"FGL_FUND_CODE" VARCHAR2(60),
"FGL_ACCT_CODE" VARCHAR2(60),
"FGL_ORGN_CODE" VARCHAR2(60),
"FGL_PROG_CODE" VARCHAR2(60),
"FGL_GRNT_YEAR" VARCHAR2(60),
"FGL_PERIOD" VARCHAR2(60),
"FGL_BUDGET" VARCHAR2(60)
)and i have a data like such
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');I bascially need to get the total of the budget column. however its not as simple as it sound(well atleast not for me.) the totals carry over to the new period. youll noticed the you have a period column. basically what im saying is that
fgl_grant_year 10 period 1 = for account 7600 its $100 and $100 for period 2 you see 100 dollars again this is not to be added this is the carried over balance. which remains $100.
so im trying to write a query that basically does the following.
im given a period for the sake of this example lets say period 1 i get nothing else. I have to find the greates grant year grab the amount for period 14(which is the total from the previous year) and add it to the amount of the current period. in this case period 1 grnt_year 11
so the expected outcome should be $700
240055 240055 7240 4730 02 10 14 200
240055 240055 7600 4730 02 10 14 100
240055 240055 7600 4730 02 11 1 400keep in mind that im not given a year just a period.
any help that you guys can offer would be immensely appreciated. I have been trying to get this to work for over 3 days now.
finally broke down and put together this post
Edited by: mlov83 on Sep 14, 2011 8:48 PMFrank
wondering if you can help me modify this sql statement that you provided me with .
table values have been modified a bit.
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');i need to take one more thing into consideration. if the greatest year has a value on period 00 i need to ignore the period 14 and the current period total would be
the current period +(current period - greatest year 00)
hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
period 2 amount $ 600
period 0 amount $ 400 - period 2 amount of $600 = 200
600+200 = $800
if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
can you please help me out.
Miguel -
Help with query calculations (recursive)
Hi All,
I want some help with a query using a base rate and the result use in the next calculation year.
Here an example:
create table rate_type(
rate_type_id number,
rate_desc nvarchar2(50),
rate_base_year number
insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (1, 'Desc1', 4.6590);
insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (2, 'Desc2', 4.6590);
create table rates (
rate_type_id number
rate_year number,
rate_value number
insert into rates(rate_type_id, rate_year, rate_value) values (1, 2012, 1.2);
insert into rates(rate_type_id, rate_year, rate_value) values (1, 2013, 1.3);
insert into rates(rate_type_id, rate_year, rate_value) values (1, 2014, 1.4);
insert into rates(rate_type_id, rate_year, rate_value) values (2, 2012, 1.2);
insert into rates(rate_type_id, rate_year, rate_value) values (2, 2013, 1.3);
insert into rates(rate_type_id, rate_year, rate_value) values (2, 2014, 1.4);The calculation for the first year should be the base rate of the rate type. The next year should use the result of the previous year and so on.
The result of my sample data is:
2012 = 4.659 + 1.2 + 4.659 * (1.2 * 0.01) = 5.9149
2013 = 5.9149 + 1.3 + 5.9149 * (1.3 * 0.01) = 7.1859
2014 = 7.1859 + 1.4 + 7.1859 * (1.4 * 0.01) = 8.4721Query result:
NAME 2012 2013 2014
Desc1 5.9149 7.1859 8.4721
Desc2 XXXX XXX XXXX
How can I do this in one select statement? Any ideas?
Thanks!Assuming you are on 11.2:
with t as (
select a.rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
count(*) over(partition by a.rate_type_id) cnt,
row_number() over(partition by a.rate_type_id order by rate_year) rn
from rate_type a,
rates b
where a.rate_type_id = b.rate_type_id
r(
rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
result
) as (
select rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
from t
where rn = 1
union all
select t.rate_type_id,
t.rate_desc,
t.rate_year,
t.rate_base_year,
t.rate_value,
t.cnt,
t.rn,
r.result + t.rate_value + r.result * t.rate_value * 0.01 result
from r,
t
where t.rate_type_id = r.rate_type_id
and t.rn = r.rn + 1
select *
from (
select rate_desc name,
rate_year,
result
from r
where rn <= cnt
pivot (sum(result) for rate_year in (2012,2013,2014))
order by name
NAME 2012 2013 2014
Desc1 5.914908 7.2918018 8.79388703
Desc2 5.914908 7.2918018 8.79388703
SQL> Obviously pivoting assumes you know rate_year values upfront. If not, then without pivoting:
with t as (
select a.rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
count(*) over(partition by a.rate_type_id) cnt,
row_number() over(partition by a.rate_type_id order by rate_year) rn
from rate_type a,
rates b
where a.rate_type_id = b.rate_type_id
r(
rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
result
) as (
select rate_type_id,
rate_desc,
rate_year,
rate_base_year,
rate_value,
cnt,
rn,
rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
from t
where rn = 1
union all
select t.rate_type_id,
t.rate_desc,
t.rate_year,
t.rate_base_year,
t.rate_value,
t.cnt,
t.rn,
r.result + t.rate_value + r.result * t.rate_value * 0.01 result
from r,
t
where t.rate_type_id = r.rate_type_id
and t.rn = r.rn + 1
select rate_desc name,
rate_year,
result
from r
where rn <= cnt
order by name,
rate_year
NAME RATE_YEAR RESULT
Desc1 2012 5.914908
Desc1 2013 7.2918018
Desc1 2014 8.79388703
Desc2 2012 5.914908
Desc2 2013 7.2918018
Desc2 2014 8.79388703
6 rows selected.
SQL> SY. -
Need Help With Query Using Aggregation
If I have a table, defined like this:
CREATE TABLE range_test
range_id NUMBER(20) NOT NULL,
grade CHAR(1) NOT NULL,
lower_bound_of_range NUMBER(5,2) NOT NULL,
upper_bound_of_range NUMBER(5,2) NOT NULL,
received_date_time_stamp TIMESTAMP DEFAULT SYSTIMESTAMP NOT NULL
And I wanted to query the table to find the range associated with the last inserted row for each 'grade' (e.g. 'A', 'B', 'C', etc), how would I go about that?
I want something like the following, but I know that this won't work right:
SELECT
grade,
lower_bounding_of_range,
upper_bounding_of_range,
max(received_date_time_stamp)
FROM
range_test GROUP BY received_date_time_stamp;
Thanks for your help. . .I'm frustrating myself with this one and I think it should be possible without having to use PL/SQL (i.e. SQL aggregate functions or sub-queries should work).Perhaps something along the lines of...
SQL> ed
Wrote file afiedt.buf
1 select deptno, empno, ename, hiredate
2 from emp
3* order by deptno, empno
SQL> /
DEPTNO EMPNO ENAME HIREDATE
10 7782 CLARK 09-JUN-1981 00:00:00
10 7839 KING 17-NOV-1981 00:00:00
10 7934 MILLER 23-JAN-1982 00:00:00
20 7369 SMITH 17-DEC-1980 00:00:00
20 7566 JONES 02-APR-1981 00:00:00
20 7788 SCOTT 19-APR-1987 00:00:00
20 7876 ADAMS 23-MAY-1987 00:00:00
20 7902 FORD 03-DEC-1981 00:00:00
30 7499 ALLEN 20-FEB-1981 00:00:00
30 7521 WARD 22-FEB-1981 00:00:00
30 7654 MARTIN 28-SEP-1981 00:00:00
30 7698 BLAKE 01-MAY-1981 00:00:00
30 7844 TURNER 08-SEP-1981 00:00:00
30 7900 JAMES 03-DEC-1981 00:00:00
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select deptno, empno, ename, hiredate
2 from (
3 select deptno, empno, ename, hiredate
4 ,row_number() over (partition by deptno order by hiredate desc) as rn
5 from emp
6 )
7 where rn = 1
8* order by deptno, empno
SQL> /
DEPTNO EMPNO ENAME HIREDATE
10 7934 MILLER 23-JAN-1982 00:00:00
20 7876 ADAMS 23-MAY-1987 00:00:00
30 7900 JAMES 03-DEC-1981 00:00:00
SQL> -
Hi,
Good day everyone! I need help writing a query. I have this table with the following data in them...
ACCT_CODE FSYR YTD_AMT
A123 11 100
A456 11 200
A123 10 50
A456 10 100I want the output to look like this:
ACCT_CODE CURRENT_YEAR(11) PRIOR_YEAR(10)
A123 100 50
A456 200 100The user will input the fiscal year and based on that input, I want to get the prior year value as well.
Thank you for all your help!!
Edited by: user5737516 on Jun 29, 2011 6:48 AM
Edited by: user5737516 on Jun 29, 2011 6:50 AMuser5737516 wrote:
Hi,
Good day everyone! I need help writing a query. I have this table with the following data in them...
ACCT_CODE FSYR YTD_AMT
A123 11 100
A456 11 200
A123 10 50
A456 10 100
I want the output to look like this:
ACCT_CODE CURRENT_YEAR PRIOR_YEAR
A123 100 50
A456 200 100
The user will input the fiscal year and based on that input, I want to get the prior year value as well.
Thank you for all your help!!what is prior year? -
Query off of Oracle using WinSql - Need help with query
I am trying to query off of Oracle using program WinSql.
I have a table(tticpr200110) that has the following sample data:
ITEM CODE T$AMNT
23500076 ACL .0049
23500076 APM 0
23500076 APO .0093
23500076 EXP .0001
23500076 RES .0072
and what I want it to look like is:
ITEM ACL APM APO EXP RES
23500076 0.0049 0 0.0093 0.0001 0.0072
(actually I need the last 2 columns added together to be MATL-but can deal with that down the road).
Seems simple enough, but I don't know to put into the columns.
Any help would be GREATLY appreciated as soon as possible would be even better.My table - tticpr200110 when it runs I get the following sample data for part number 23500076:
The first coloumn ITEM is the part number.
The second column CODE is 1 of 5 different cost codes
The third column is the cost for that code for that part.
ITEM CODE AMNT
23500076 ACL 0.0049
23500076 APM 0.0000
23500076 APO 0.0093
23500076 EXP 0.0001
23500076 RES 0.0072
I want to make a query that makes the data look like this:
ITEM ACL APM APO EXP RES
23500076 0.0049 0.0000 0.0093 0.0001 0.0072
(similar to a pivot table in excel or acess)
I hope this helps better.
Thanks! -
Need help with Query to determine Credit Memos and Invoices
Hi All
Thanks for all the help here.
I need a query to determine any credits or invoices issued within a given period.
OINV and ORIN with UNION ALL?
Please advise any help.
Thank you!Hi Daniel,
Please check below Query.
SELECT T0.[DocNum] as 'Invice No', T0.[DocDate] as 'Invoice Date', T0.[CardName] as 'Invoiced Customer', T3.[DocNum] as 'Credit Memo No', T3.[DocDate] as 'Credit Mamo Date', T3.[CardName] as 'Credit Memo Customer' FROM OINV T0 LEFT JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry] LEFT JOIN RIN1 T2 ON T2.[BaseEntry] = T1.[DocEntry] AND T2.[BaseLine] = T1.[LineNum] LEFT JOIN ORIN T3 ON T2.[DocEntry] = T3.[DocEntry] WHERE T0.[DocDate] >=[%3] AND T0.[DocDate] <=[%4]
Hope this helps
Regards::::
Atul Chakraborty
Maybe you are looking for
-
Hi Since we downloaded the latest version of iOS on our iPad and iPhone, and synchronized our music collection in the Cloud, we can no longer see on our iPad and iPhone the music from our CD's that we have on our home computer's iTunes library. We c
-
Cannot Vew Footage on my NTSC Monitor from FCP
I am having trouble viewing my NTSC screen for recording a project to a BETA. I have gone into EasySetup and selected both Blackmagic DeckLink NTSC 8 and 10 bit. Went into View, Vew Playback and tried selecting Blackmagic NTSC 8 and 10 bit and still
-
Wireless Development Tutorial Part I HELP!!!
i relatively new to java and am trying to complete this simple tutorial using the J2ME Wireless Toolkit. It seems straightforward but for some reason every time i compile it i get the following error messages: Project settings saved Building "HelloSu
-
Printing Arabic(Hindi) numbers in oracle Report.
Hi, I would like to print Arabic(Hindi) numbers in the reports eg:*1234567890* on metalink i found that i need to set REPORTS_ARABIC_NUMERAL=HINDI REPORTS_BIDI_ALGORITHM=UNICODE in reports.sh which i already set and restarted the CM. But did not work
-
i have i mac and still have apple care series : W8602P4TU2P and you can see the problem i have got here : http://www.tienpow.com/apple-broken/ I have all the error image show to you and when i go to support in thailand they do nothing for me.. please