How to ignore nulls in analytic functions ( row_number() and count())
how to ignore nulls in analytic functions ( row_number() and count())
Iam attaching test data can any one help me please
thanks in advanceeeee
CREATE TABLE TEMP_table
ACCTNUM NUMBER,
l_DATE TIMESTAMP(3),
CODE VARCHAR2(35 BYTE),
VENDOR VARCHAR2(35 BYTE)
insert into temp_table values (1,sysdate+1/60,'bso','v1');
insert into temp_table values (1,sysdate+2/60,'bsof','v1');
insert into temp_table values (1,sysdate+3/60,'bsof','v2');
insert into temp_table values (1,sysdate+4/60,'','v1');
ian executing this my ;
SELECT acctnum,l_date,vendor,code_1,
CASE
WHEN code = 'bsof'
AND COUNT (DISTINCT code) OVER (PARTITION BY acctnum, vendor) > 1
AND row_number () OVER (PARTITION BY acctnum, vendor ORDER BY vendor, l_date) != 1
THEN 'yes'
ELSE 'no' END result
FROM (select acctnum,l_date,vendor, code code_1, case when code IN ('bso', 'bsof') then code
else null end code from TEMP_TABLE
ORDER BY acctnum ,l_date);
my result :
1 3/23/2011 5:24:34.000 PM v1 bso no
1 3/23/2011 5:48:36.000 PM v1 bsof yes
1 3/23/2011 6:36:41.000 PM v1 bsof yes
1 3/24/2011 11:55:53.000 AM v1 no
1 3/23/2011 6:12:38.000 PM v2 bsof no
I need to eliminate nulls in top query not in inner query (not using where condition in inner query)
[\code]
Similar Messages
-
How to achive this using analytical function-- please help
version 10g.
this code works just fine with my requirement. i am tyring to learn analytical functions and implement that in the below query. i tried using row_number ,
but i could nt achive the desired results. please give me some ideas.
SELECT c.tax_idntfctn_nmbr irs_number, c.legal_name irs_name,
f.prvdr_lctn_iid
FROM tax_entity_detail c,
provider_detail e,
provider_location f,
provider_location_detail pld
WHERE c.tax_entity_sid = e.tax_entity_sid
AND e.prvdr_sid = f.prvdr_sid
AND pld.prvdr_lctn_iid = f.prvdr_lctn_iid
AND c.oprtnl_flag = 'A'
AND c.status_cid = 2
AND e.oprtnl_flag = 'A'
AND e.status_cid = 2
AND (c.from_date) =
(SELECT MAX (c1.from_date)
FROM tax_entity_detail c1
WHERE c1.tax_entity_sid = c.tax_entity_sid
AND c1.oprtnl_flag = 'A'
AND c1.status_cid = 2)
AND (e.from_date) =
(SELECT MAX (c1.from_date)
FROM provider_detail c1
WHERE c1.prvdr_sid = e.prvdr_sid
AND c1.oprtnl_flag = 'A'
AND c1.status_cid = 2)
AND pld.oprtnl_flag = 'A'
AND pld.status_cid = 2
AND (pld.from_date) =
(SELECT MAX (a1.from_date)
FROM provider_location_detail a1
WHERE a1.prvdr_lctn_iid = pld.prvdr_lctn_iid
AND a1.oprtnl_flag = 'A'
AND a1.status_cid = 2)thanks
Edited by: new learner on May 24, 2010 7:53 AM
Edited by: new learner on May 24, 2010 10:50 AMMay be like this not tested...
select *
from
SELECT c.tax_idntfctn_nmbr irs_number, c.legal_name irs_name,
f.prvdr_lctn_iid, c.from_date as c_from_date, max(c.from_date) over(partition by c.tax_entity_sid) as max_c_from_date,
e.from_date as e_from_date, max(e.from_date) over(partition by e.prvdr_sid) as max_e_from_date,
pld.from_date as pld_from_date, max(pld.from_date) over(partition by pld.prvdr_lctn_iid) as max_pld_from_date
FROM tax_entity_detail c,
provider_detail e,
provider_location f,
provider_location_detail pld
WHERE c.tax_entity_sid = e.tax_entity_sid
AND e.prvdr_sid = f.prvdr_sid
AND pld.prvdr_lctn_iid = f.prvdr_lctn_iid
AND c.oprtnl_flag = 'A'
AND c.status_cid = 2
AND e.oprtnl_flag = 'A'
AND e.status_cid = 2
AND pld.oprtnl_flag = 'A'
AND pld.status_cid = 2
)X
where c_from_date=max_c_from_date AND e_from_date =max_e_from_date AND
pld_from_date=max_pld_from_date -
How to retrieve data from a function module and use it in sap script??
I have a report program, which calls a function module. This function module internally calls an include program. In this program, I have a variable which is to be used in the sap script. How can I send this variable to the sap script
Hi,
In your case, Include prog is part of FM, no need to treat it as an Entity.
Now, Your Answer -
In SCRIPT - IN Page Window -->
PERFORM GET_MVAT_TIN IN PROGRAM Z_SCRIPT_PERFORMS_ABAPDB3
USING &VBDKR-KUNRE&
CHANGING &STCD1&
CHANGING &STCD2&
ENDPERFORM
IF &STCD1& <> ' '
<B>MVAT Number :</> &STCD1&
ENDIF
Then go to SE38 --> Creat prog with type - Subroutine pool
In that Write FORM statement for this PERFORM.
FORM get_mvat_tin TABLES inttab STRUCTURE itcsy
outtab STRUCTURE itcsy.
DATA : v_kunre TYPE kna1-kunnr,
v_stcd1 TYPE kna1-stcd1,
v_stcd2 TYPE kna1-stcd2.
LOOP AT outtab.
CLEAR outtab-value.
MODIFY outtab.
ENDLOOP.
READ TABLE inttab INDEX 1.
v_kunre = inttab-value.
IF v_kunre CA sy-abcde.
ELSE.
UNPACK v_kunre TO v_kunre.
ENDIF.
" Here You can take your Funcion module ***************************
SELECT SINGLE stcd1 stcd2 FROM kna1 INTO (v_stcd1, v_stcd2)
WHERE kunnr = v_kunre.
IF sy-subrc = 0.
READ TABLE outtab INDEX 1.
WRITE v_stcd1 TO outtab-value.
MODIFY outtab INDEX 1.
READ TABLE outtab INDEX 2.
WRITE v_stcd2 TO outtab-value.
MODIFY outtab INDEX 2.
ENDIF.
ENDFORM. -
How to Create a batch file to display and count specific words in log file
Hi All,
I have requirement Program to be written that will go through a log file and look for following key words.
Unexpected Essbase error
And also it will count the # of times the word error appear in a log file.
You may use batch file or Perl script to complete this task.
e.g. in the log file - It will flag yes that keyword "Unexpected Essbase error" found and word error occurs 9 times.
Pls help me in know process to achieve above requirement.
and pls let me know what is perl scripting ?
Thanks in Advance
Regards,
SMSorry but it sounds like you have been asked to do something and you have pasted the requirement on the forum, have you done any research to find out which scripting language you are going to use or any find examples, there are so many differents examples and help on the internet it just takes a little bit of time and investment.
Cheers
John
http://john-goodwin.blogspot.com/ -
HOw to Get the top level of Hierarchy and count on that basis
hi
i have following tables
desc hr_organizations_units_V
organization_id PRIMARY KEY
name
ORGANIZATION_type
per_org_structure_elements
organization_id_parent FK TO hr_organizations_units_V(ORGANIZATION_ID)
organization_id_child FK TO hr_organizations_units_V(ORGANIZATION_ID)
I HAVE THIS QUERY TO GET PARENT CHILD
SELECT ORGANIZATION_ID_PARENT PARENT,ORGANIZATION_ID_CHILD CHILD,ORGANIZATION_TYPE FROM PER_ORG_STRUCTURE_ELEMENTS OSE,HR_ALL_ORGANIZATION_UNITS AOU WHERE AOU.ORGANIZATION_ID = OSE.ORGANIZATION_ID_CHILD CONNECT BY PRIOR ORGANIZATION_ID_CHILD = ORGANIZATION_ID_PARENT
START WITH ORGANIZATION_ID_PARENT = 82 -- THE GRAND PARENT
ORDER BY ORGANIZATION_ID_PARENT
PARENT CHILD ORGANIZATION_TYPE
82 83 COMPANY
82 143 COMPANY
83 84 DIVISION
83 134 DEPARTMENT
83 135 DEPARTMENT
DESC per_all_assignments_f
ASSIGNMENT_NUMBER
ORGANIZATION_ID FORIGN KEY TO HR_ALL_ORGANIZATION_UNITS
THE ASSIGNMENTS ARE ASSIGNED ON DEPARTMENT LEVEL.
MY REQUIREMENT IS THAT I WANT TO GET THE
1)TOTAL NO OF ASSIGNMENTS ON THE DIVISION LEVEL
2)TOTAL NO OF ASSIGNMENTS ON THE COMPANY LEVEL
3)REPORTS LIKE PAY SLIP ETC I WANT TO GET THE ABOVE TWO LEVELS OF ORGANIZATION FOR EACH EMPLOYEE I.E DIVISION AND COMPANY OF
OF THE EMPLOYEE'S DEPARTMENT.
I WILL REALLY APPRECIATE ANY HELPING HAND.
REGARDSHere are a few ways to get what I think you are asking for now. If this is not what you want, then please provide a complete example of what you want, including sample data, and the complete query result, including numbers, based on that data, that you want, as I have done below.
scott@ORA92> -- test data:
scott@ORA92> SELECT * FROM hr_all_organization_units
2 /
ORGANIZATION_ID NAME ORGANIZATIO
82 GRANDPARENT GRANDPARENT
83 COMPANY 83 COMPANY
84 DIVISION 84 DIVISION
134 DEPARTMENT 134 DEPARTMENT
135 DEPARTMENT 135 DEPARTMENT
143 COMPANY 143 COMPANY
6 rows selected.
scott@ORA92> SELECT * FROM per_org_structure_elements
2 /
ORGANIZATION_ID_PARENT ORGANIZATION_ID_CHILD
82 83
82 143
83 84
84 134
84 135
scott@ORA92> SELECT * FROM per_all_assignments_f
2 /
ASSIGNMENT_NUMBER ORGANIZATION_ID
1 83
2 84
3 134
4 135
5 143
6 84
6 rows selected.
scott@ORA92> -- method 1:
scott@ORA92> COLUMN name FORMAT A35
scott@ORA92> SELECT RPAD ('.', 5 * (LEVEL - 1), '.') || aou.name AS name,
2 (SELECT SUM (the_count)
3 FROM (SELECT organization_id_parent,
4 organization_id_child,
5 COUNT (*) AS the_count
6 FROM per_org_structure_elements,
7 per_all_assignments_f
8 WHERE per_org_structure_elements.organization_id_child =
9 per_all_assignments_f.organization_id
10 GROUP BY organization_id_parent,
11 organization_id_child) t
12 START WITH t.organization_id_child =
13 ose.organization_id_child
14 CONNECT BY PRIOR t.organization_id_child =
15 t.organization_id_parent) AS assignments_count
16 FROM PER_ORG_STRUCTURE_ELEMENTS OSE,
17 HR_ALL_ORGANIZATION_UNITS AOU
18 WHERE AOU.ORGANIZATION_ID = OSE.ORGANIZATION_ID_CHILD
19 START WITH aou.name = '&company_name'
20 CONNECT BY PRIOR ose.ORGANIZATION_ID_CHILD = ose.ORGANIZATION_ID_PARENT
21 /
Enter value for company_name: COMPANY 83
old 19: START WITH aou.name = '&company_name'
new 19: START WITH aou.name = 'COMPANY 83'
NAME ASSIGNMENTS_COUNT
COMPANY 83 5
.....DIVISION 84 4
..........DEPARTMENT 134 1
..........DEPARTMENT 135 1
scott@ORA92> -- method 2:
scott@ORA92> COLUMN name FORMAT A35
scott@ORA92> WITH sub_query AS
2 (SELECT ose.organization_id_parent, ose.organization_id_child,
3 aou.name, COUNT (*) AS assignments
4 FROM per_org_structure_elements ose,
5 hr_all_organization_units aou,
6 per_all_assignments_f aaf
7 WHERE ose.organization_id_child = aou.organization_id
8 AND ose.organization_id_child = aaf.organization_id
9 AND aou.organization_id = aaf.organization_id
10 GROUP BY ose.organization_id_parent, ose.organization_id_child, aou.name)
11 SELECT RPAD ('.', 5 * (LEVEL - 1), '.') || name AS name,
12 (select SUM (assignments)
13 from sub_query
14 start with organization_id_child = t.organization_id_child
15 connect by prior organization_id_child = organization_id_parent)
16 AS assignments_count
17 FROM sub_query t
18 START WITH name = '&company_name'
19 CONNECT BY PRIOR ORGANIZATION_ID_CHILD = ORGANIZATION_ID_PARENT
20 /
Enter value for company_name: COMPANY 83
old 18: START WITH name = '&company_name'
new 18: START WITH name = 'COMPANY 83'
NAME ASSIGNMENTS_COUNT
COMPANY 83 5
.....DIVISION 84 4
..........DEPARTMENT 134 1
..........DEPARTMENT 135 1
scott@ORA92> -- method 3:
scott@ORA92> COLUMN name FORMAT A35
scott@ORA92> CREATE OR REPLACE VIEW sub_query AS
2 SELECT ose.organization_id_parent, ose.organization_id_child,
3 aou.name, COUNT (*) AS assignments
4 FROM per_org_structure_elements ose,
5 hr_all_organization_units aou,
6 per_all_assignments_f aaf
7 WHERE ose.organization_id_child = aou.organization_id
8 AND ose.organization_id_child = aaf.organization_id
9 AND aou.organization_id = aaf.organization_id
10 GROUP BY ose.organization_id_parent, ose.organization_id_child, aou.name
11 /
View created.
scott@ORA92> SELECT RPAD ('.', 5 * (LEVEL - 1), '.') || name AS name,
2 (select SUM (assignments)
3 from sub_query
4 start with organization_id_child = t.organization_id_child
5 connect by prior organization_id_child = organization_id_parent)
6 AS assignments_count
7 FROM sub_query t
8 START WITH name = '&company_name'
9 CONNECT BY PRIOR ORGANIZATION_ID_CHILD = ORGANIZATION_ID_PARENT
10 /
Enter value for company_name: COMPANY 83
old 8: START WITH name = '&company_name'
new 8: START WITH name = 'COMPANY 83'
NAME ASSIGNMENTS_COUNT
COMPANY 83 5
.....DIVISION 84 4
..........DEPARTMENT 134 1
..........DEPARTMENT 135 1 -
HTMLDB 1.6 and "order by" in analytic functions
In HTMLDB 1.6, oracle 10g, when i enter the string "order by" in the region source of a report of the type "sql query (pl/sql function body returning sql query", I get
1 error has occurred
* Your query can't include an "ORDER BY" clause when having column heading sorting enabled.
I understand the reason for this error, but unfortunately i need this for an analytic function:
row_number() over (partition by ... order by ...)
It seems that the check is performed by simply looking for the string "order by" in the "region source" (in fact the error fires even if that string is contained within a comment).
I know possible workarounds (eg creating a view and select'ing from it), i just wanted to let you know.
Regards
AlbertoAnother one under the 'obvious route' category:
Seems that the ORDER BY check is apparentl for ORDER<space>BY... so simply adding extra whitespace between ORDER and BY bypasses the check (at least in 2.1.0.00.39).
To make it a bit more obious that a separation is intended, an empty comment, i.e. ORDER/*/BY*, works nicely
Edited by: mcstock on Nov 19, 2008 10:29 AM -
Using analytical function - value with highest count
Hi
i have this table below
CREATE TABLE table1
( cust_name VARCHAR2 (10)
, txn_id NUMBER
, txn_date DATE
, country VARCHAR2 (10)
, flag number
, CONSTRAINT key1 UNIQUE (cust_name, txn_id)
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9870,TO_DATE ('15-Jan-2011', 'DD-Mon-YYYY'), 'Iran', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9871,TO_DATE ('16-Jan-2011', 'DD-Mon-YYYY'), 'China', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9872,TO_DATE ('17-Jan-2011', 'DD-Mon-YYYY'), 'China', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9873,TO_DATE ('18-Jan-2011', 'DD-Mon-YYYY'), 'Japan', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9874,TO_DATE ('19-Jan-2011', 'DD-Mon-YYYY'), 'Japan', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9875,TO_DATE ('20-Jan-2011', 'DD-Mon-YYYY'), 'Russia', 1);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9877,TO_DATE ('22-Jan-2011', 'DD-Mon-YYYY'), 'China', 0);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9878,TO_DATE ('26-Jan-2011', 'DD-Mon-YYYY'), 'Korea', 0);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9811,TO_DATE ('17-Jan-2011', 'DD-Mon-YYYY'), 'China', 0);
INSERT INTO table1 (cust_name, txn_id, txn_date,country,flag) VALUES ('Peter', 9854,TO_DATE ('13-Jan-2011', 'DD-Mon-YYYY'), 'Taiwan', 0);
The requirement is to create an additional column in the resultset with country name where the customer has done the maximum number of transactions
(with transaction flag 1). In case we have two or more countries tied with the same count, then we need to select the country (among the tied ones)
where the customer has done the last transaction (with transaction flag 1)
e.g. The count is 2 for both 'China' and 'Japan' for transaction flag 1 ,and the latest transaction is for 'Japan'. So the new column should contain 'Japan'
CUST_NAME TXN_ID TXN_DATE COUNTRY FLAG country_1
Peter 9811 17-JAN-11 China 0 Japan
Peter 9854 13-JAN-11 Taiwan 0 Japan
Peter 9870 15-JAN-11 Iran 1 Japan
Peter 9871 16-JAN-11 China 1 Japan
Peter 9872 17-JAN-11 China 1 Japan
Peter 9873 18-JAN-11 Japan 1 Japan
Peter 9874 19-JAN-11 Japan 1 Japan
Peter 9875 20-JAN-11 Russia 1 Japan
Peter 9877 22-JAN-11 China 0 Japan
Peter 9878 26-JAN-11 Korea 0 Japan
Please let me know how to accomplish this using analytical functions
Thanks
-LearnsequelDoes this work (not spent much time checking it)?
WITH ana AS (
SELECT cust_name, txn_id, txn_date, country, flag,
Sum (flag)
OVER (PARTITION BY cust_name, country) n_trx,
Max (CASE WHEN flag = 1 THEN txn_date END)
OVER (PARTITION BY cust_name, country) l_trx
FROM cnt_trx
SELECT cust_name, txn_id, txn_date, country, flag,
First_Value (country) OVER (PARTITION BY cust_name ORDER BY n_trx DESC, l_trx DESC) top_cnt
FROM ana
CUST_NAME TXN_ID TXN_DATE COUNTRY FLAG TOP_CNT
Fred 9875 20-JAN-11 Russia 1 Russia
Fred 9874 19-JAN-11 Japan 1 Russia
Peter 9873 18-JAN-11 Japan 1 Japan
Peter 9874 19-JAN-11 Japan 1 Japan
Peter 9872 17-JAN-11 China 1 Japan
Peter 9871 16-JAN-11 China 1 Japan
Peter 9811 17-JAN-11 China 0 Japan
Peter 9877 22-JAN-11 China 0 Japan
Peter 9875 20-JAN-11 Russia 1 Japan
Peter 9870 15-JAN-11 Iran 1 Japan
Peter 9878 26-JAN-11 Korea 0 Japan
Peter 9854 13-JAN-11 Taiwan 0 Japan
12 rows selected. -
[8i] Subquery vs Multiple Analytic Functions
Does anyone have an idea which is better performance-wise?
I have a query that is 3 layers deep already with sub-queries. In the topmost level, I have a choice. I can calculate one analytic function twice, and one analytic function three times, or I can make the topmost level into a subquery, and calculate each analytic function only once.
In case it matters for this problem, this query is running on an 8i database.
A simplified example:
CREATE TABLE my_data
( order_no CHAR(10)
, seq_nbr CHAR(4)
, area_id CHAR(4)
, start_date DATE
, unit_time NUMBER(7,2)
INSERT INTO my_data VALUES ('0000567890','0010','A001',TO_DATE('05/01/2000','mm/dd/yyyy'),0.34);
INSERT INTO my_data VALUES ('0000567890','0020','A001',TO_DATE('05/02/2000','mm/dd/yyyy'),0.78);
INSERT INTO my_data VALUES ('0000567890','0030','A002',TO_DATE('05/03/2000','mm/dd/yyyy'),0.91);
INSERT INTO my_data VALUES ('0000567890','0040','A003',TO_DATE('05/03/2000','mm/dd/yyyy'),0.27);
INSERT INTO my_data VALUES ('0000123456','0010','A001',TO_DATE('04/01/2001','mm/dd/yyyy'),0.39);
INSERT INTO my_data VALUES ('0000123456','0020','A001',TO_DATE('04/02/2001','mm/dd/yyyy'),0.98);
INSERT INTO my_data VALUES ('0000123456','0030','A002',TO_DATE('04/03/2001','mm/dd/yyyy'),0.77);
INSERT INTO my_data VALUES ('0000123456','0040','A003',TO_DATE('04/03/2001','mm/dd/yyyy'),0.28);
INSERT INTO my_data VALUES ('0000123123','0010','A001',TO_DATE('12/01/2001','mm/dd/yyyy'),0.31);
INSERT INTO my_data VALUES ('0000123123','0020','A001',TO_DATE('12/02/2001','mm/dd/yyyy'),0.86);
INSERT INTO my_data VALUES ('0000123123','0030','A002',TO_DATE('12/03/2001','mm/dd/yyyy'),0.82);
INSERT INTO my_data VALUES ('0000123123','0040','A003',TO_DATE('12/03/2001','mm/dd/yyyy'),0.23);
INSERT INTO my_data VALUES ('0000111111','0010','A001',TO_DATE('06/01/2002','mm/dd/yyyy'),0.29);
INSERT INTO my_data VALUES ('0000111111','0020','A001',TO_DATE('06/02/2002','mm/dd/yyyy'),0.84);
INSERT INTO my_data VALUES ('0000111111','0030','A002',TO_DATE('06/03/2002','mm/dd/yyyy'),0.78);
INSERT INTO my_data VALUES ('0000111111','0040','A003',TO_DATE('06/03/2002','mm/dd/yyyy'),0.26);
INSERT INTO my_data VALUES ('0000654321','0010','A001',TO_DATE('05/01/2003','mm/dd/yyyy'),0.28);
INSERT INTO my_data VALUES ('0000654321','0020','A001',TO_DATE('05/02/2003','mm/dd/yyyy'),0.88);
INSERT INTO my_data VALUES ('0000654321','0030','A002',TO_DATE('05/03/2003','mm/dd/yyyy'),0.75);
INSERT INTO my_data VALUES ('0000654321','0040','A003',TO_DATE('05/03/2003','mm/dd/yyyy'),0.25);My choices for the example are:
SELECT area_id
, period_start
, period_end
, AVG(tot_area_unit_hrs)
OVER (
PARTITION BY area_id
ORDER BY period_start
RANGE BETWEEN period_end - period_start PRECEDING
AND CURRENT ROW
STDDEV(tot_area_unit_hrs)
OVER (
PARTITION BY area_id
ORDER BY period_start
RANGE BETWEEN period_end - period_start PRECEDING
AND CURRENT ROW
) AS lo_unit_time
, AVG(tot_area_unit_hrs)
OVER (
PARTITION BY area_id
ORDER BY period_start
RANGE BETWEEN period_end - period_start PRECEDING
AND CURRENT ROW
) AS avg_unit_time
, AVG(tot_area_unit_hrs)
OVER (
PARTITION BY area_id
ORDER BY period_start
RANGE BETWEEN period_end - period_start PRECEDING
AND CURRENT ROW
) +
STDDEV(tot_area_unit_hrs)
OVER (
PARTITION BY area_id
ORDER BY period_start
RANGE BETWEEN period_end - period_start PRECEDING
AND CURRENT ROW
) AS hi_unit_time
FROM (
SELECT order_no
, area_id
, ADD_MONTHS(MIN(start_date),-24)+1 AS period_start
, MIN(start_date) AS period_end
, SUM(unit_time) AS tot_area_unit_hrs
FROM my_data
GROUP BY order_no
, area_id
ORDER BY area_id
, period_end
;or
SELECT area_id
, period_start
, period_end
, avg_unit_time - stdev_unit_time AS lo_unit_time
, avg_unit_time
, avg_unit_time + stdev_unit_time AS hi_unit_time
FROM (
SELECT area_id
, period_start
, period_end
, STDDEV(tot_area_unit_hrs)
OVER (
PARTITION BY area_id
ORDER BY period_start
RANGE BETWEEN period_end - period_start PRECEDING
AND CURRENT ROW
) AS stdev_unit_time
, AVG(tot_area_unit_hrs)
OVER (
PARTITION BY area_id
ORDER BY period_start
RANGE BETWEEN period_end - period_start PRECEDING
AND CURRENT ROW
) AS avg_unit_time
FROM (
SELECT order_no
, area_id
, ADD_MONTHS(MIN(start_date),-24)+1 AS period_start
, MIN(start_date) AS period_end
, SUM(unit_time) AS tot_area_unit_hrs
FROM my_data
GROUP BY order_no
, area_id
ORDER BY area_id
, period_end
;My gut instinct would be that the 2nd option is faster (with the sub-query), but before I try this on my actual data set which is much larger, I'd like a second opinion. I don't want to accidentally start running a "neverending" query.Sorry for the delay in response here... I was busy deleting 39 GB of trace files, because some silly person (hangs head in shame) accidentally set TRACE_LEVEL_CLIENT=SUPPORT months ago and forgot to turn it off, and didn't notice until her hard drive was full and she couldn't save a file.....
Anyway...
@Dev
For the real query...
option 1 explain plan:
OPERATION OPTIONS OBJECT_NODE OBJECT_OWNER OBJECT_NAME OBJECT_INSTANCE OBJECT_TYPE OPTIMIZER ID PARENT_ID POSITION COST CARDINALITY BYTES
SELECT STATEMENT REMOTE HINT: CHOOSE 0 6076 6076 1 91
SORT ORDER BY 1 0 1 6076 1 91
WINDOW SORT 2 1 1 1 91
SORT GROUP BY 3 2 1 6076 1 91
FILTER 4 3 1
NESTED LOOPS 5 4 1 6071 1 91
TABLE ACCESS FULL DB8I.WORLD ASCHEMA DETAILS 2 6 5 1 6068 1 50
INDEX RANGE SCAN DB8I.WORLD ASCHEMA ORDERS_IX3 UNIQUE ANALYZED 7 5 2 3 141930 5819130
TABLE ACCESS BY INDEX ROWID DB8I.WORLD ASCHEMA DETAILS 3 8 4 2 7 1 44
INDEX RANGE SCAN DB8I.WORLD ASCHEMA DETAILS_IX1 NON-UNIQUE ANALYZED 9 8 1 3 1 option 2 explain plan:
OPERATION OPTIONS OBJECT_NODE OBJECT_OWNER OBJECT_NAME OBJECT_INSTANCE OBJECT_TYPE OPTIMIZER ID PARENT_ID POSITION COST CARDINALITY BYTES
SELECT STATEMENT HINT: CHOOSE 0 2777 2777 96 14208
SORT ORDER BY 1 0 1 2777 96 14208
VIEW LOCALUSER 1 2 1 1 2776 96 14208
WINDOW SORT 3 2 1 2776 96 26400
HASH GROUP BY 4 3 1 2776 96 26400
FILTER 5 4 1
REMOTE DB8I REMOTE 6 5 1 1908 386 59830
REMOTE DB8I DETAILS REMOTE 7 5 2 4 1 129 You should know, in order to get explain plan on these queries, I have to run them via a database link to the 8i database through XE 10g on my local machine, as I don't have access to run explain plan on the remote database itself. I've never seen my local user name appear before in an explain plan run this way, but it did in the one for option #2 (subquery), so I'd guess that wouldn't be the explain plan I'd get if I ran it just in the 8i database. I also find it really odd that the ORDERS table doesn't seem to be referenced in the 2nd explain plan... I do think that's still going to be my best option though, so I'm going to try it and hope it doesn't take too long.
@Frank Kulash
Agreed. That's what I'll try, and I also think that I can't put the analytic function in with the aggregates, without having to do some additional computations in that sub-query, which I think would defeat the purpose of putting them there in the first place. -
Functional Area and Grant Fields on work Order
Hi Experts,
I want to know, how would I hide / set optional Functional area and Grant fields?
There fields are appeared on IW31 (Header data tab -> GOTO -> Assignments -> Funds Management)
Best Regards,Hi,
I am going to perform FI Vs PM integration, In our case if funds are available then I can be planned and execute maintenance order, We have very experience resource in FI and that consultant advised me to set off these fields.
What is GuiXT? from where I can use this? how I will use this?
Regards, -
How to obtain system form's type and count?
Hi all
i wish to open a system form by calling the GetForm method of the Forms collection.
My question is how do i know the form's type and count in order to get it?
appreciate the help
YoavTo open Activity form, you need to have the menuUID.
in order to get it , Click on View of the toolbar, and then System Information
(or CtrlShiftD)
Now I guess you know you have more information about items in forms and menu on the bottom left corner of Business One.
Then in the toolbar, click on Modules, Business Partnet, and put the mouse on the menu Activty.
You will see in the bottom left corner the value:Menu Uid = 2563
HTH
Sebastien -
Understanding row_number() and using it in an analytic function
Dear all;
I have been playing around with row_number and trying to understand how to use it and yet I still cant figure it out...
I have the following code below
create table Employee(
ID VARCHAR2(4 BYTE) NOT NULL,
First_Name VARCHAR2(10 BYTE),
Last_Name VARCHAR2(10 BYTE),
Start_Date DATE,
End_Date DATE,
Salary Number(8,2),
City VARCHAR2(10 BYTE),
Description VARCHAR2(15 BYTE)
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values ('01','Jason', 'Martin', to_date('19960725','YYYYMMDD'), to_date('20060725','YYYYMMDD'), 1234.56, 'Toronto', 'Programmer');
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('02','Alison', 'Mathews', to_date('19760321','YYYYMMDD'), to_date('19860221','YYYYMMDD'), 6661.78, 'Vancouver','Tester')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('03','James', 'Smith', to_date('19781212','YYYYMMDD'), to_date('19900315','YYYYMMDD'), 6544.78, 'Vancouver','Tester')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('04','Celia', 'Rice', to_date('19821024','YYYYMMDD'), to_date('19990421','YYYYMMDD'), 2344.78, 'Vancouver','Manager')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('05','Robert', 'Black', to_date('19840115','YYYYMMDD'), to_date('19980808','YYYYMMDD'), 2334.78, 'Vancouver','Tester')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('06','Linda', 'Green', to_date('19870730','YYYYMMDD'), to_date('19960104','YYYYMMDD'), 4322.78,'New York', 'Tester')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('07','David', 'Larry', to_date('19901231','YYYYMMDD'), to_date('19980212','YYYYMMDD'), 7897.78,'New York', 'Manager')
insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
values('08','James', 'Cat', to_date('19960917','YYYYMMDD'), to_date('20020415','YYYYMMDD'), 1232.78,'Vancouver', 'Tester')I did a simple select statement
select * from Employee e
and it returns this below
ID FIRST_NAME LAST_NAME START_DAT END_DATE SALARY CITY DESCRIPTION
01 Jason Martin 25-JUL-96 25-JUL-06 1234.56 Toronto Programmer
02 Alison Mathews 21-MAR-76 21-FEB-86 6661.78 Vancouver Tester
03 James Smith 12-DEC-78 15-MAR-90 6544.78 Vancouver Tester
04 Celia Rice 24-OCT-82 21-APR-99 2344.78 Vancouver Manager
05 Robert Black 15-JAN-84 08-AUG-98 2334.78 Vancouver Tester
06 Linda Green 30-JUL-87 04-JAN-96 4322.78 New York Tester
07 David Larry 31-DEC-90 12-FEB-98 7897.78 New York Manager
08 James Cat 17-SEP-96 15-APR-02 1232.78 Vancouver TesterI wrote another select statement with row_number. see below
SELECT first_name, last_name, salary, city, description, id,
ROW_NUMBER() OVER(PARTITION BY description ORDER BY city desc) "Test#"
FROM employee
and I get this result
First_name last_name Salary City Description ID Test#
Celina Rice 2344.78 Vancouver Manager 04 1
David Larry 7897.78 New York Manager 07 2
Jason Martin 1234.56 Toronto Programmer 01 1
Alison Mathews 6661.78 Vancouver Tester 02 1
James Cat 1232.78 Vancouver Tester 08 2
Robert Black 2334.78 Vancouver Tester 05 3
James Smith 6544.78 Vancouver Tester 03 4
Linda Green 4322.78 New York Tester 06 5
I understand the partition by which means basically for each associated group a unique number wiill be assigned for that row, so in this case since tester is one group, manager is another group, and programmer is another group then tester gets its own unique number for each row, manager as well and etc.What is throwing me off is the order by and how this numbering are assigned. why is
1 assigned to Alison Mathews for the tester group and 2 assigned to James Cat and 3 assigned Robert Black
I apologize if this is a stupid question, i have tried reading about it online and looking at the oracle documentation but that still dont fully understand why.user13328581 wrote:
understanding row_number() and using it in an analytic functionROW_NUMBER () IS an analytic fucntion. Are you trying to use the results of ROW_NUMBER in another analytic function? If so, you need a sub-query. Analuytic functions can't be nested within other analytic functions.
...I have the following code below
... I did a simple select statementThanks for posting all that! It's really helpful.
... and I get this result
First_name last_name Salary City Description ID Test#
Celina Rice 2344.78 Vancouver Manager 04 1
David Larry 7897.78 New York Manager 07 2
Jason Martin 1234.56 Toronto Programmer 01 1
Alison Mathews 6661.78 Vancouver Tester 02 1
James Cat 1232.78 Vancouver Tester 08 2
Robert Black 2334.78 Vancouver Tester 05 3
James Smith 6544.78 Vancouver Tester 03 4
Linda Green 4322.78 New York Tester 06 5... What is throwing me off is the order by and how this numbering are assigned. why is
1 assigned to Alison Mathews for the tester group and 2 assigned to James Cat and 3 assigned Robert Black That's determined by the analytic ORDER BY clause. Yiou said "ORDER BY city desc", so a row where city='Vancouver' will get a lower namber than one where city='New York', since 'Vancouver' comes after 'New York' in alphabetic order.
If you have several rows that all have the same city, then you can be sure that ROW_NUMBER will assign them consecutive numbers, but it's arbitrary which one of them will be lowest and which highest. For example, you have 5 'Tester's: 4 from Vancouver and 1 from New York. There's no particular reason why the one with first_name='Alison' got assinge 1, and 'James' got #2. If you run the same query again, without changing the table at all, then 'Robert' might be #1. It's certain that the 4 Vancouver rows will be assigned numbers 1 through 4, but there's no way of telling which of those 4 rows will get which of those 4 numbers.
Similar to a query's ORDER BY clause, the analytic ORDER BY clause can have two or more expressions. The N-th one will only be considered if there was a tie for all (N-1) earlier ones. For example "ORDER BY city DESC, last_name, first_name" would mena 'Vancouver' comes before 'New York', but, if multiple rows all have city='Vancouver', last_name would determine the order: 'Black' would get a lower number than 'Cat'. If you had multiple rows with city='Vancouver' and last_name='Black', then the order would be determined by first_name. -
Nth_value() function with IGNORE NULLS in oracle 10g
Is there any easy way to mimic ORACLE 11g nth_value() function with IGNORE NULLS clause in 10g or earlier Oracle release?
SQL> select ename,
2 sal,
3 nth_value(sal,5) over() fifth_min_sal
4 from emp
5 order by sal
6 /
ENAME SAL FIFTH_MIN_SAL
SMITH 800 1250
JAMES 950 1250
ADAMS 1100 1250
WARD 1250 1250
MARTIN 1250 1250
MILLER 1300 1250
TURNER 1500 1250
ALLEN 1600 1250
CLARK 2450 1250
BLAKE 2850 1250
JONES 2975 1250
ENAME SAL FIFTH_MIN_SAL
SCOTT 3000 1250
FORD 3000 1250
KING 5000 1250
14 rows selected.
SQL> select ename,
2 sal,
3 min(case rn when 5 then sal end) over() fifth_min_sal
4 from (
5 select ename,
6 sal,
7 row_number() over(order by sal nulls last) rn
8 from emp
9 )
10 order by sal
11 /
ENAME SAL FIFTH_MIN_SAL
SMITH 800 1250
JAMES 950 1250
ADAMS 1100 1250
WARD 1250 1250
MARTIN 1250 1250
MILLER 1300 1250
TURNER 1500 1250
ALLEN 1600 1250
CLARK 2450 1250
BLAKE 2850 1250
JONES 2975 1250
ENAME SAL FIFTH_MIN_SAL
SCOTT 3000 1250
FORD 3000 1250
KING 5000 1250
14 rows selected.
SQL> SY. -
How to use analytic function with aggregate function
hello
can we use analytic function and aggrgate function in same qurey? i tried to find any example on Net but not get any example how both of these function works together. Any link or example plz share with me
Edited by: Oracle Studnet on Nov 15, 2009 10:29 PMselect
t1.region_name,
t2.division_name,
t3.month,
t3.amount mthly_sales,
max(t3.amount) over (partition by t1.region_name, t2.division_name)
max_mthly_sales
from
region t1,
division t2,
sales t3
where
t1.region_id=t3.region_id
and
t2.division_id=t3.division_id
and
t3.year=2004
Source:http://www.orafusion.com/art_anlytc.htm
Here max (aggregate) and over partition by (analytic) function is in same query. So it means we can use aggregate and analytic function in same query and more than one analytic function in same query also.
Hth
Girish Sharma -
How can we write this in analytical function..
select a.employee_id,a.last_name,b.count from employees a, (select manager_id, count(manager_id) as count from employees group by manager_id) b where a.employee_id=b.manager_id;
As per my requirement I need each manager name and no of employees reporting to him... above query works.. Could anybody help to write the same using analytic function.... Hw this same can be written in effiect way??? (quick performance)
Please also share the link to download some doc to have good understanding of analytical function..
Thanks in advance....are you trying to do a hierarchical type of query?
select ename, count(ename) -1 numr_of_emps_under_this_mgr from emp
connect by empno =prior mgr
group by ename
order by count(ename) desc ;
ENAME NUMR_OF_EMPS_UNDER_THIS_MGR
KING 13
BLAKE 5
JONES 4
CLARK 1
FORD 1
SCOTT 1
ADAMS 0
TURNER 0
MARTIN 0
JAMES 0
SMITH 0
MILLER 0
ALLEN 0
WARD 0Here is the table structure I used (I think you can download it from oracle somewhere)
CREATE TABLE EMP
EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10 BYTE),
JOB VARCHAR2(9 BYTE),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2)
SET DEFINE OFF;
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7369, 'SMITH', 'CLERK', 7902, TO_DATE('12/17/1980 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
800, 20);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
Values
(7499, 'ALLEN', 'SALESMAN', 7698, TO_DATE('02/20/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1600, 300, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
Values
(7521, 'WARD', 'SALESMAN', 7698, TO_DATE('02/22/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1250, 500, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7566, 'JONES', 'MANAGER', 7839, TO_DATE('04/02/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
2975, 20);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
Values
(7654, 'MARTIN', 'SALESMAN', 7698, TO_DATE('09/28/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1250, 1400, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7698, 'BLAKE', 'MANAGER', 7839, TO_DATE('05/01/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
2850, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7782, 'CLARK', 'MANAGER', 7839, TO_DATE('06/09/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
2450, 10);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7788, 'SCOTT', 'ANALYST', 7566, TO_DATE('12/09/1982 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
3000, 20);
Insert into EMP
(EMPNO, ENAME, JOB, HIREDATE, SAL, DEPTNO)
Values
(7839, 'KING', 'PRESIDENT', TO_DATE('11/17/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
5000, 10);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
Values
(7844, 'TURNER', 'SALESMAN', 7698, TO_DATE('09/08/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1500, 0, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7876, 'ADAMS', 'CLERK', 7788, TO_DATE('01/12/1983 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1100, 20);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7900, 'JAMES', 'CLERK', 7698, TO_DATE('12/03/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
950, 30);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7902, 'FORD', 'ANALYST', 7566, TO_DATE('12/03/1981 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
3000, 20);
Insert into EMP
(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, DEPTNO)
Values
(7934, 'MILLER', 'CLERK', 7782, TO_DATE('01/23/1982 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),
1300, 10);
COMMIT; -
How can rewrite the Query using Analytical functions ?
Hi,
I have the SQL script as shown below ,
SELECT cd.cardid, cd.cardno,TT.TRANSACTIONTYPECODE,TT.TRANSACTIONTYPEDESC DESCRIPTION,
SUM (NVL (CASE tt.transactiontypecode
WHEN 'LOAD_ACH'
THEN th.transactionamount
END, 0)
) AS load_ach,
SUM
(NVL (CASE tt.transactiontypecode
WHEN 'FUND_TRANSFER_RECEIVED'
THEN th.transactionamount
END,
0
) AS Transfersin,
( SUM (NVL (CASE tt.transactiontypecode
WHEN 'FTRNS'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'SEND_MONEY'
THEN th.transactionamount
END, 0)
)) AS Transferout,
SUM (NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_ACH'
THEN th.transactionamount
END, 0)
) AS withdrawal_ach,
SUM (NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_CHECK'
THEN th.transactionamount
END, 0)
) AS withdrawal_check,
( SUM (NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_CHECK_FEE'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'REJECTED_ACH_LOAD_FEE'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_ACH_REV'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_CHECK_REV'
THEN th.transactionamount
END,
0
) +
SUM
(NVL (CASE tt.transactiontypecode
WHEN 'WITHDRAWAL_CHECK_FEE_REV'
THEN th.transactionamount
END,
0
) +
SUM
(NVL (CASE tt.transactiontypecode
WHEN 'REJECTED_ACH_LOAD_FEE_REV'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'OVERDRAFT_FEE_REV'
THEN th.transactionamount
END, 0)
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'STOP_CHECK_FEE_REV'
THEN th.transactionamount
END,
0
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'LOAD_ACH_REV'
THEN th.transactionamount
END, 0)
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'OVERDRAFT_FEE'
THEN th.transactionamount
END, 0)
) +
SUM (NVL (CASE tt.transactiontypecode
WHEN 'STOP_CHECK_FEE'
THEN th.transactionamount
END, 0)
)) AS Fee,
th.transactiondatetime
FROM carddetail cd,
transactionhistory th,
transactiontype tt,
(SELECT rmx_a.cardid, rmx_a.endingbalance prev_balance, rmx_a.NUMBEROFDAYS
FROM rmxactbalreport rmx_a,
(SELECT cardid, MAX (reportdate) reportdate
FROM rmxactbalreport
GROUP BY cardid) rmx_b
WHERE rmx_a.cardid = rmx_b.cardid AND rmx_a.reportdate = rmx_b.reportdate) a
WHERE th.transactiontypeid = tt.transactiontypeid
AND cd.cardid = th.cardid
AND cd.cardtype = 'P'
AND cd.cardid = a.cardid (+)
AND CD.CARDNO = '7116734387812758335'
--AND TT.TRANSACTIONTYPECODE = 'FUND_TRANSFER_RECEIVED'
GROUP BY cd.cardid, cd.cardno, numberofdays,th.transactiondatetime,tt.transactiontypecode,TT.TRANSACTIONTYPEDESC
Ouput of the above query is :
CARDID CARDNO TRANSACTIONTYPECODE DESCRIPTION LOAD_ACH TRANSFERSIN TRANSFEROUT WITHDRAWAL_ACH WITHDRAWAL_CHECK FEE TRANSACTIONDATETIME
6005 7116734387812758335 FUND_TRANSFER_RECEIVED Fund Transfer Received 0 3.75 0 0 0 0 21/09/2007 11:15:38 AM
6005 7116734387812758335 FUND_TRANSFER_RECEIVED Fund Transfer Received 0 272 0 0 0 0 05/10/2007 9:12:37 AM
6005 7116734387812758335 WITHDRAWAL_ACH Withdraw Funds via ACH 0 0 0 300 0 0 24/10/2007 3:43:54 PM
6005 7116734387812758335 SEND_MONEY Fund Transfer Sent 0 0 1 0 0 0 19/09/2007 1:17:48 PM
6005 7116734387812758335 FUND_TRANSFER_RECEIVED Fund Transfer Received 0 1 0 0 0 0 18/09/2007 7:25:23 PM
6005 7116734387812758335 LOAD_ACH Prepaid Deposit via ACH 300 0 0 0 0 0 02/10/2007 3:00:00 AM
I want the output like for Load_ACH there should be one record etc.,
Can any one help me , how can i rewrite the above query using analytical functions .,
SekharNot sure of your requirements but this mayhelp reduce your code;
<untested>
SUM (
CASE
WHEN tt.transactiontypecode IN
('WITHDRAWAL_CHECK_FEE', 'REJECTED_ACH_LOAD_FEE', 'WITHDRAWAL_ACH_REV', 'WITHDRAWAL_CHECK_REV',
'WITHDRAWAL_CHECK_FEE_REV', 'REJECTED_ACH_LOAD_FEE_REV', 'OVERDRAFT_FEE_REV','STOP_CHECK_FEE_REV',
'LOAD_ACH_REV', 'OVERDRAFT_FEE', 'STOP_CHECK_FEE')
THEN th.transactionamount
ELSE 0) feeAlso, you might want to edit your post and use [pre] and [/pre] tags around your code for formatting.
Maybe you are looking for
-
I have installed the new version 13, called Aurora. I am currently using it, but if I start not liking the new features (so far I do! But I have to ask) can I "go back" to the "good old" Firefox 11? Will I be loosing my data and settings? History and
-
Blurb books: accuracy of spot color in Lightroom 4 vs Photoshop
Within the Blub book module of Lightroom 4, if you want to have a color block or color type, you can specify that color with a color picker that displays the color you've chosen according to RGB values. When I input those exact same RGB values into P
-
How to find the Model size in Semantics
Hi All, Please can you tell me how to find the model size in Semantics. Thanks, Indu
-
Monitoring Index without rows in v$object_usage !!!
Hello Gurus, OS - Solaris Oracle - 92 I was generating a ddlscript to start monitoring index usage, I've run the sql below : @db92 > alter index INTRANET.PK_OWPDO MONITORING USAGE 2 ; Index altered. When I query the table V$OBJECT_USAGE i don't see a
-
")S 9.2.2 only for machines that have OS X installed"???
My sister has a G4 Sawtooth (no special enhancements). A mistake was made during installation, and a "clean install" was not done, resulting in her losing all of her 3rd party extensions , Outlook mail, addresses, etc. She's reinstalled some of the p