How this query executing internally
Dear All,
This query picks the nth highest paid employee details, we can acheive this by rank or desnse_rank functions also
But those execution is easily understandable.But Iam not able to understand , how this below correlated subquery executing internally .Please help me on this query
select * from emp a where &n=(select count(distinnct b.sal) from emp b where a.sal<=b.sal)
Thanks in advance
>
how this below correlated subquery executing internally .Please help me on this queryPlease check the Explain plan.
Explain plan
set pagesize 25
set linesize 121
EXPLAIN PLAN FOR
< Your Query >;
SELECT * FROM TABLE(dbms_xplan.display);Example :-
SQL> EXPLAIN PLAN FOR select count(1) from dual;
Explained.
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 323232323
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------
Similar Messages
-
How this procedure works INTERNALLY???
HI Experts
I have created the below procedure(It is updating 50 million records in decent time) but I have few doubts.
1) I am not commiting till the end. Will it take up the UNDO space. How can I assure that this procedure executes till the end.
2) If i have to increase the UNDO space how should I increase considering 50 million rows.
3) Do I have to consider factors other than UNDO space while running this procedure if yes then wat are they.
4) Suggest me some links where i can find out how sql queries and pl/sql objects works internally.
CREATE OR REPLACE PROCEDURE ACCOUNTS_MIGRATION
IS
TYPE num_new_typ IS TABLE OF accounts.acc_no_new%TYPE ;
TYPE num_old_typ IS TABLE OF accounts.acc_no_old%TYPE ;
TYPE mat_records_typ IS TABLE OF mbk_audittrail.account1%TYPE;
TYPE mat_records_typ_1 IS TABLE OF mbk_audittrail.account2%TYPE;
TYPE mr_records_typ IS TABLE OF mbk_requests.account_no%TYPE;
TYPE mpgn_records_typ IS TABLE OF Mtx_payment_gateway_txn.PAYMENT_METHOD_NUMBER%TYPE;
TYPE mti_records_typ IS TABLE OF Mtx_transaction_items.ACCOUNT_ID%TYPE;
all_num_new num_new_typ:= num_new_typ();
all_num_old num_old_typ:= num_old_typ();
mat_records mat_records_typ:= mat_records_typ();
mat_records_1 mat_records_typ_1:= mat_records_typ_1();
mr_records mr_records_typ:= mr_records_typ();
mpgn_records mpgn_records_typ:= mpgn_records_typ();
mti_records mti_records_typ:= mti_records_typ();
BEGIN
SELECT ACC_NO_OLD, ACC_NO_NEW bulk collect into all_num_old,all_num_new FROM ACCOUNTS;
SELECT distinct ACCOUNT1 bulk collect INTO mat_records FROM MBK_AUDITTRAIL where account1 <> ' ';
SELECT distinct ACCOUNT2 bulk collect INTO mat_records_1 FROM MBK_AUDITTRAIL where account2 <> ' ';
SELECT distinct account_no bulk collect INTO mr_records FROM Mbk_requests where account_no <> ' ';
SELECT distinct PAYMENT_METHOD_NUMBER bulk collect INTO mpgn_records FROM Mtx_payment_gateway_txn where PAYMENT_METHOD_NUMBER <> ' ';
SELECT distinct ACCOUNT_ID bulk collect INTO mti_records FROM Mtx_transaction_items where ACCOUNT_ID <> ' ';
FORALL i IN 1..mat_records.count
UPDATE MBK_AUDITTRAIL SET ACCOUNT1=(SELECT ACC_NO_NEW FROM ACCOUNTS WHERE ACC_NO_OLD=mat_records(i) AND ROWNUM=1) WHERE ACCOUNT1=mat_records(i);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows updated for MBK_AUDITTRAIL->ACCOUNT1');
FORALL j IN 1..mat_records_1.count
UPDATE MBK_AUDITTRAIL SET ACCOUNT2=(SELECT ACC_NO_NEW FROM ACCOUNTS WHERE ACC_NO_OLD=mat_records_1(j) AND ROWNUM=1) WHERE ACCOUNT2=mat_records(j);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows updated for MBK_AUDITTRAIL->ACCOUNT2');
FORALL k IN 1..all_num_old.count
UPDATE MBK_BANK SET ACCOUNT_NO=all_num_new(k) WHERE ACCOUNT_NO=all_num_old(k);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows updated for MBK_BANK->ACCOUNT_NO');
FORALL l IN 1..all_num_old.count
UPDATE MBK_CUST_ACCOUNTS SET ACCOUNT_NO=all_num_new(l) WHERE ACCOUNT_NO=all_num_old(l);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows updated for MBK_CUST_ACCOUNTS->ACCOUNT_NO');
FORALL m IN 1..all_num_old.count
UPDATE Mtx_Payment_methods SET PAYMENT_METHOD_NUMBER=all_num_new(m) WHERE PAYMENT_METHOD_NUMBER=all_num_old(m);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows updated for Mtx_Payment_methods->PAYMENT_METHOD_NUMBER');
FORALL n IN 1..mr_records.count
UPDATE Mbk_requests SET ACCOUNT_NO=(SELECT ACC_NO_NEW FROM ACCOUNTS WHERE ACC_NO_OLD=mr_records(n) AND ROWNUM=1) WHERE ACCOUNT_NO=mr_records(n);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows updated for Mbk_requests->ACCOUNT_NO');
FORALL o IN 1..mpgn_records.count
UPDATE Mtx_payment_gateway_txn SET PAYMENT_METHOD_NUMBER=(SELECT ACC_NO_NEW FROM ACCOUNTS WHERE ACC_NO_OLD=mpgn_records(o) AND ROWNUM=1) WHERE PAYMENT_METHOD_NUMBER=mpgn_records(o);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows updated for Mtx_payment_gateway_txn->PAYMENT_METHOD_NUMBER');
FORALL p IN 1..mti_records.count
UPDATE Mtx_transaction_items SET ACCOUNT_ID=(SELECT ACC_NO_NEW FROM ACCOUNTS WHERE ACC_NO_OLD=mti_records(p) AND ROWNUM=1) WHERE ACCOUNT_ID=mti_records(p);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows updated for Mtx_transaction_items->ACCOUNT_ID');
FORALL q IN 1..all_num_old.count
UPDATE Temp_customer_mgmt SET ACCOUNT_NO=all_num_new(q) WHERE ACCOUNT_NO=all_num_old(q);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows updated for Temp_customer_mgmt->ACCOUNT_NO');
FORALL r IN 1..all_num_old.count
UPDATE MTX_HIST_PIN_REGENERATION SET ACCOUNT_NO=all_num_new(r) WHERE ACCOUNT_NO=all_num_old(r);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows updated for MTX_HIST_PIN_REGENERATION->ACCOUNT_NO');
END;Thanks & Regards
Saurabh SharmaRemember that besides UNDO you also have to worry about redo !
If you create a new session for every test run at each volume level, you can query V$SESSTAT for the statistiic 'redo size' so as to identify the Bytes of Redo for each volume level. And then extrapolate from there !
Hemant K Chitale
http://hemantoracledba.blogspot.com
Edited by: Hemant K Chitale on Jul 20, 2009 5:02 PM : ADDED Signature -
Can you please explain how this query is fetching the rows?
here is a query to find the top 3 salaries. But the thing is that i am now able to understand how its working to get the correct data :How the data in the alias table P1 and P2 getting compared. Can you please explain in some steps.
SELECT MIN(P1.SAL) FROM PSAL P1, PSAL P2
WHERE P1.SAL >= P2.SAL
GROUP BY P2.SAL
HAVING COUNT (DISTINCT P1.SAL) <=3 ;
here is the data i used :
SQL> select * from psal;
NAME SAL
able 1000
baker 900
charles 900
delta 800
eddy 700
fred 700
george 700
george 700
Regards,
Renu... Please help me in understanding the query.
Your query looks like anything but a Top-N query.
If you run it in steps and analyze the output at the end of each step, then you should be able to understand what it does.
Given below is some brief information on the same:
test@ora>
test@ora> --
test@ora> -- Query 1 - using the non-equi (theta) join
test@ora> --
test@ora> with psal as (
2 select 'able' as name, 1000 as sal from dual union all
3 select 'baker', 900 from dual union all
4 select 'charles', 900 from dual union all
5 select 'delta', 800 from dual union all
6 select 'eddy', 700 from dual union all
7 select 'fred', 700 from dual union all
8 select 'george', 700 from dual union all
9 select 'george', 700 from dual)
10 --
11 SELECT p1.sal AS p1_sal, p1.NAME AS p1_name, p2.sal AS p2_sal,
12 p2.NAME AS p2_name
13 FROM psal p1, psal p2
14 WHERE p1.sal >= p2.sal;
P1_SAL P1_NAME P2_SAL P2_NAME
1000 able 1000 able
1000 able 900 baker
1000 able 900 charles
1000 able 800 delta
1000 able 700 eddy
1000 able 700 fred
1000 able 700 george
1000 able 700 george
900 baker 900 baker
900 baker 900 charles
900 baker 800 delta
900 baker 700 eddy
900 baker 700 fred
900 baker 700 george
900 baker 700 george
900 charles 900 baker
900 charles 900 charles
900 charles 800 delta
900 charles 700 eddy
900 charles 700 fred
900 charles 700 george
900 charles 700 george
800 delta 800 delta
800 delta 700 eddy
800 delta 700 fred
800 delta 700 george
800 delta 700 george
700 eddy 700 eddy
700 eddy 700 fred
700 eddy 700 george
700 eddy 700 george
700 fred 700 eddy
700 fred 700 fred
700 fred 700 george
700 fred 700 george
700 george 700 eddy
700 george 700 fred
700 george 700 george
700 george 700 george
700 george 700 eddy
700 george 700 fred
700 george 700 george
700 george 700 george
43 rows selected.
test@ora>
test@ora>This query joins PSAL with itself using a non equi-join. Take each row of PSAL p1 and see how it compares with PSAL p2. You'll see that:
- Row 1 with sal 1000 is >= to all sal values of p2, so it occurs 8 times
- Row 2 with sal 900 is >= to 9 sal values of p2, so it occurs 7 times
- Row 3: 7 times again... and so on.
- So, total no. of rows are: 8 + 7 + 7 + 5 + 4 + 4 + 4 + 4 = 43
test@ora>
test@ora> --
test@ora> -- Query 2 - add the GROUP BY
test@ora> --
test@ora> with psal as (
2 select 'able' as name, 1000 as sal from dual union all
3 select 'baker', 900 from dual union all
4 select 'charles', 900 from dual union all
5 select 'delta', 800 from dual union all
6 select 'eddy', 700 from dual union all
7 select 'fred', 700 from dual union all
8 select 'george', 700 from dual union all
9 select 'george', 700 from dual)
10 --
11 SELECT p2.sal AS p2_sal,
12 COUNT(*) as cnt,
13 COUNT(p1.sal) as cnt_p1_sal,
14 COUNT(DISTINCT p1.sal) as cnt_dist_p1_sal,
15 MIN(p1.sal) as min_p1_sal,
16 MAX(p1.sal) as max_p1_sal
17 FROM psal p1, psal p2
18 WHERE p1.sal >= p2.sal
19 GROUP BY p2.sal;
P2_SAL CNT CNT_P1_SAL CNT_DIST_P1_SAL MIN_P1_SAL MAX_P1_SAL
700 32 32 4 700 1000
800 4 4 3 800 1000
900 6 6 2 900 1000
1000 1 1 1 1000 1000
test@ora>
test@ora>Now, if you group by p2.sal in the output of query 1, and check the number of distinct p1.sal, min of p1.sal etc. you see that for p2.sal values - 800, 900 and 1000, there are 3 or less p1.sal values associated.
So, the last 3 rows are the ones you are interested in, essentially. As follows:
test@ora>
test@ora> --
test@ora> -- Query 3 - GROUP BY and HAVING
test@ora> --
test@ora> with psal as (
2 select 'able' as name, 1000 as sal from dual union all
3 select 'baker', 900 from dual union all
4 select 'charles', 900 from dual union all
5 select 'delta', 800 from dual union all
6 select 'eddy', 700 from dual union all
7 select 'fred', 700 from dual union all
8 select 'george', 700 from dual union all
9 select 'george', 700 from dual)
10 --
11 SELECT p2.sal AS p2_sal,
12 COUNT(*) as cnt,
13 COUNT(p1.sal) as cnt_p1_sal,
14 COUNT(DISTINCT p1.sal) as cnt_dist_p1_sal,
15 MIN(p1.sal) as min_p1_sal,
16 MAX(p1.sal) as max_p1_sal
17 FROM psal p1, psal p2
18 WHERE p1.sal >= p2.sal
19 GROUP BY p2.sal
20 HAVING COUNT(DISTINCT p1.sal) <= 3;
P2_SAL CNT CNT_P1_SAL CNT_DIST_P1_SAL MIN_P1_SAL MAX_P1_SAL
800 4 4 3 800 1000
900 6 6 2 900 1000
1000 1 1 1 1000 1000
test@ora>
test@ora>
test@ora>That's what you are doing in that query.
The thing is - in order to find out Top-N values, you simply need to scan that one table PSAL. So, joining it to itself is not necessary.
A much simpler query is as follows:
test@ora>
test@ora>
test@ora> --
test@ora> -- Top-3 salaries - distinct or not; using ROWNUM on ORDER BY
test@ora> --
test@ora> with psal as (
2 select 'able' as name, 1000 as sal from dual union all
3 select 'baker', 900 from dual union all
4 select 'charles', 900 from dual union all
5 select 'delta', 800 from dual union all
6 select 'eddy', 700 from dual union all
7 select 'fred', 700 from dual union all
8 select 'george', 700 from dual union all
9 select 'george', 700 from dual)
10 --
11 SELECT sal
12 FROM (
13 SELECT sal
14 FROM psal
15 ORDER BY sal DESC
16 )
17 WHERE rownum <= 3;
SAL
1000
900
900
test@ora>
test@ora>
test@ora>And for Top-3 distinct salaries:
test@ora>
test@ora> --
test@ora> -- Top-3 DISTINCT salaries; using ROWNUM on ORDER BY on DISTINCT
test@ora> --
test@ora> with psal as (
2 select 'able' as name, 1000 as sal from dual union all
3 select 'baker', 900 from dual union all
4 select 'charles', 900 from dual union all
5 select 'delta', 800 from dual union all
6 select 'eddy', 700 from dual union all
7 select 'fred', 700 from dual union all
8 select 'george', 700 from dual union all
9 select 'george', 700 from dual)
10 --
11 SELECT sal
12 FROM (
13 SELECT DISTINCT sal
14 FROM psal
15 ORDER BY sal DESC
16 )
17 WHERE rownum <= 3;
SAL
1000
900
800
test@ora>
test@ora>
test@ora>You may also want to check out the RANK and DENSE_RANK analytic functions.
RANK:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions123.htm#SQLRF00690
DENSE_RANK:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions043.htm#SQLRF00633
HTH
isotope -
WITH
MEMBER [FYDay].[DateHierarchy].[CurrentDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PreviousDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .PREVMEMBER }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay1] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(1) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay2] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(2) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay3] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(3) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay4] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(4) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay5] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(5) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay6] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(6) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay7] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(7) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FPERIOD],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[WTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FWEEK],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
SELECT
[FYDay].[DateHierarchy].[WTD],
[FYDay].[DateHierarchy].[PTD],
[FYDay].[DateHierarchy].[PreviousDay],
[FYDay].[DateHierarchy].[CurrentDay],
[FYDay].[DateHierarchy].[CurrentDay1],
[FYDay].[DateHierarchy].[CurrentDay2],
[FYDay].[DateHierarchy].[CurrentDay3],
[FYDay].[DateHierarchy].[CurrentDay4],
[FYDay].[DateHierarchy].[CurrentDay5],
[FYDay].[DateHierarchy].[CurrentDay6],
[FYDay].[DateHierarchy].[CurrentDay7]
} ON COLUMNS,
[Measures].[Store Budget],
[MEASURES].[SNAPSHOTSOLDAMOUNT],
[MEASURES].[SHIPPEDAMOUNT],
[MEASURES].[SHIPPED VS SOLD],
[Measures].[% To Budget]
{[STOREMASTER].[SERVICINGDC].[SERVICINGDC].ALLMEMBERS}
)} ON ROWS
from ( select {[STOREMASTER].[SERVICINGDC].&[Houston]} on columns
FROM [Model]Hi Ramparasad,
In your query, you add a measures and dimension on Row axis which is not supported in query designer in SSRS. Please use the query below.
WITH
MEMBER [FYDay].[DateHierarchy].[CurrentDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PreviousDay] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .PREVMEMBER }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay1] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(1) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay2] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(2) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay3] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(3) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay4] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(4) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay5] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(5) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay6] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(6) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[CurrentDay7] AS AGGREGATE(
{ [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(7) }
, [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[PTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FPERIOD],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
MEMBER [FYDay].[DateHierarchy].[WTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FWEEK],
[FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
), [Measures].CURRENTMEMBER)
SELECT
[Measures].[Store Budget],
[MEASURES].[SNAPSHOTSOLDAMOUNT],
[MEASURES].[SHIPPEDAMOUNT],
[MEASURES].[SHIPPED VS SOLD],
[Measures].[% To Budget]
}ON COLUMNS,
{ [FYDay].[DateHierarchy].[WTD],
[FYDay].[DateHierarchy].[PTD],
[FYDay].[DateHierarchy].[PreviousDay],
[FYDay].[DateHierarchy].[CurrentDay],
[FYDay].[DateHierarchy].[CurrentDay1],
[FYDay].[DateHierarchy].[CurrentDay2],
[FYDay].[DateHierarchy].[CurrentDay3],
[FYDay].[DateHierarchy].[CurrentDay4],
[FYDay].[DateHierarchy].[CurrentDay5],
[FYDay].[DateHierarchy].[CurrentDay6],
[FYDay].[DateHierarchy].[CurrentDay7]
{[STOREMASTER].[SERVICINGDC].[SERVICINGDC].ALLMEMBERS}
} ON ROWS
from ( select {[STOREMASTER].[SERVICINGDC].&[Houston]} on columns
FROM [Model]
Regards,
Charlie Liao
TechNet Community Support -
class c is an abstract class n the class a extends c. Inside the main method of class a I have a reference to class c n the object of class a. When I execute the print statement it print c that mean method in the abstract class. But I create the object for the concrete class which extends the abstract class. Seems like the object was created for the abstract class. How could that happen. Can some one help me . Thanks in advance.
abstract class c{
public static void cc(){
System.out.println("c");
public class a extends c{
public static void cc(){
System.out.println("a");
public static void main(String args[]){
c obj=new a();
obj.cc();
}I found the solution for that. That's because static KW. Even I create the object of concrete class the reference is abstract class. Since the method is static that method call. If I remove that sub class method get called.
-
Hi all,
I have placed some repeating conditions in many places of the query , Please suggest me to reduce the size of the query .
SELECT (CASE
WHEN prs.rqst_ctgry_lkpcd <> 'AR'
AND prp.x12_code_list_qlfr_lkpcd <> 'HC'
THEN prp.x12_code_list_qlfr_lkpcd
END
) x12_code_list_qlfr_lkpcd,
(CASE
WHEN prs.rqst_ctgry_lkpcd <> 'AR'
AND prp.x12_code_list_qlfr_lkpcd <> 'HC'
THEN (SELECT prcdr_code
FROM PROCEDURE
WHERE procedure_iid = prp.procedure_iid) end) procedure_iid,
(CASE
WHEN prs.rqst_ctgry_lkpcd <> 'AR'
AND prp.x12_code_list_qlfr_lkpcd <> 'HC'
THEN prp.mdfr_code end) mdfr_code, (CASE
WHEN prs.rqst_ctgry_lkpcd <> 'AR'
AND prp.x12_code_list_qlfr_lkpcd <> 'HC'
THEN prp.mdfr2_code end) mdfr2_code,
(CASE
WHEN prs.rqst_ctgry_lkpcd <> 'AR'
AND prp.x12_code_list_qlfr_lkpcd <> 'HC'
THEN prp.mdfr3_code end) mdfr3_code, (CASE
WHEN prs.rqst_ctgry_lkpcd <> 'AR'
AND prp.x12_code_list_qlfr_lkpcd <> 'HC'
THEN prp.mdfr4_code end) mdfr4_code,
(CASE
WHEN prs.rqst_ctgry_lkpcd <> 'AR'
AND prp.x12_code_list_qlfr_lkpcd <> 'HC'
THEN prp.drug_desc end) drug_desc, (CASE
WHEN prs.rqst_ctgry_lkpcd <> 'AR'
AND prp.x12_code_list_qlfr_lkpcd <> 'HC'
THEN prsi.sv308 end) product_service_id,
(CASE
WHEN prs.rqst_ctgry_lkpcd <> 'AR'
AND prp.x12_code_list_qlfr_lkpcd <> 'HC'
THEN
(CASE
WHEN LENGTH (SUBSTR (prpt.rqst_prcdr_amt,
INSTR (prpt.rqst_prcdr_amt, '.', 1, 1),
1
) = 1
THEN prpt.rqst_prcdr_amt || '0'
ELSE prpt.rqst_prcdr_amt || ''
END
) end) rqst_prcdr_amt,
prp.oral_cavity_dsgntn2_cid oral_cavity_dsgntn2_cid,
prp.oral_cavity_dsgntn3_cid oral_cavity_dsgntn3_cid,
prp.oral_cavity_dsgntn4_cid oral_cavity_dsgntn4_cid,
prp.oral_cavity_dsgntn5_cid oral_cavity_dsgntn5_cid,
prp.prosthesis_crown_inlay_code prosthesis_crown_inlay_code,
(CASE
WHEN prs.rqst_ctgry_lkpcd <> 'AR'
AND prp.x12_code_list_qlfr_lkpcd <> 'HC'
THEN prpt.rqst_prcdr_units end) rqst_prcdr_units, prp.remark remark
FROM (SELECT pa_rqst_sid,
MAX (DECODE (meta_data_cid, 9715, data_value, '')) sv308
FROM pa_request_situational
GROUP BY pa_rqst_sid) prsi,
pa_transaction_request ptr,
input_acknwldgmnt ia,
input_batch_file ibf,
pa_request pr,
pa_request_service prs,
pa_request_procedure prp,
pa_rqst_prcdr_transaction prpt
WHERE ptr.input_acknwldgmnt_sid = ia.input_acknwldgmnt_sid
AND ia.input_batch_file_sid = ibf.input_batch_file_sid
AND ptr.pa_trnsctn_rqst_sid = pr.pa_trnsctn_rqst_sid
AND pr.pa_rqst_sid = prs.pa_rqst_sid
AND prs.pa_rqst_srvc_sid = prp.pa_rqst_srvc_sid
AND prp.pa_rqst_prcdr_sid = prpt.pa_rqst_prcdr_sid
AND pr.pa_rqst_sid = prsi.pa_rqst_sid
AND pr.oprtnl_flag = 'A'
AND prs.oprtnl_flag = 'A'
AND ptr.oprtnl_flag = 'A'
AND prp.oprtnl_flag = 'A'
AND prpt.oprtnl_flag = 'A'
AND ibf.original_file_name =?
Thanks,
P PrakashA few days ago, you were already suggested to use the WITH statement.
Did you try using the WITH statement?
Sybrand Bakker
Senior Oracle DBA -
[8i] Query with lots of subqueries: a simpler way to do this query?
Ok, so generally, my problem is that I can't figure out how to write this query without including a bunch of copies of the same subquery (similar to having to join multiple copies of a table). Basically, I have to get information that's in rows in one table into columns in the results of my query. I've created sample tables, with insert statements for sample data, and a trimmed-down version of the query I'm running against those (2) tables. I'll explain what I mean by "trimmed-down" where I provide the SQL for that query.
My restrictions:
1) I'm running in 8i
2) I cannot create any tables in the database (I can only do read-only queries and create views).
Here are my sample tables and sample data:
CREATE TABLE reqs
( req_id NUMBER NOT NULL,
part_no VARCHAR2(5),
req_date DATE,
req_qty NUMBER,
CONSTRAINT reqs_pk PRIMARY KEY (req_id)
INSERT INTO reqs
VALUES (1,'part1',To_Date('01/01/2010','mm/dd/yyyy'),5);
INSERT INTO reqs
VALUES (2,'part2',To_Date('01/10/2010','mm/dd/yyyy'),25);
INSERT INTO reqs
VALUES (3,'part1',To_Date('01/20/2010','mm/dd/yyyy'),3);
INSERT INTO reqs
VALUES (4,'part2',To_Date('02/01/2010','mm/dd/yyyy'),15);
INSERT INTO reqs
VALUES (5,'other',To_Date('02/05/2010','mm/dd/yyyy'),1);
INSERT INTO reqs
VALUES (6,'part1',To_Date('02/07/2010','mm/dd/yyyy'),10);
INSERT INTO reqs
VALUES (7,'part3',To_Date('02/25/2010','mm/dd/yyyy'),22);
INSERT INTO reqs
VALUES (8,'part1',To_Date('03/01/2010','mm/dd/yyyy'),24);
INSERT INTO reqs
VALUES (9,'part3',To_Date('04/01/2010','mm/dd/yyyy'),12);
CREATE TABLE part
( part_no VARCHAR2(5) NOT NULL,
part_desc VARCHAR2(25),
qty_instock NUMBER,
CONSTRAINT part_pk PRIMARY KEY (part_no)
INSERT INTO part
VALUES ('part1','description 1 here',5);
INSERT INTO part
VALUES ('part2','description 2 here',10);
INSERT INTO part
VALUES ('part3','description 3 here',0);Now, here is the query I'm running against the two tables:
SELECT part.part_no
, part.part_desc
, part.qty_instock
, pd.tot_req_qty AS qty_past_due
, m1.tot_req_qty AS qty_this_month
, m2.tot_req_qty AS qty_next_month
, m3.tot_req_qty AS qty_month_3
FROM part
SELECT reqs.part_no
, SUM(reqs.req_qty) AS tot_req_qty
, CASE
WHEN reqs.req_date < sysdate
THEN 'Past Due'
ELSE To_Char(reqs.req_date,'MON-yyyy')
END AS month_reqd
FROM reqs
GROUP BY reqs.part_no
, CASE
WHEN reqs.req_date < sysdate
THEN 'Past Due'
ELSE To_Char(reqs.req_date,'MON-yyyy')
END
) pd --for past due
SELECT reqs.part_no
, SUM(reqs.req_qty) AS tot_req_qty
, CASE
WHEN reqs.req_date < sysdate
THEN 'Past Due'
ELSE To_Char(reqs.req_date,'MON-yyyy')
END AS month_reqd
FROM reqs
GROUP BY reqs.part_no
, CASE
WHEN reqs.req_date < sysdate
THEN 'Past Due'
ELSE To_Char(reqs.req_date,'MON-yyyy')
END
) m1 --for month 1
SELECT reqs.part_no
, SUM(reqs.req_qty) AS tot_req_qty
, CASE
WHEN reqs.req_date < sysdate
THEN 'Past Due'
ELSE To_Char(reqs.req_date,'MON-yyyy')
END AS month_reqd
FROM reqs
GROUP BY reqs.part_no
, CASE
WHEN reqs.req_date < sysdate
THEN 'Past Due'
ELSE To_Char(reqs.req_date,'MON-yyyy')
END
) m2 --for month 2
SELECT reqs.part_no
, SUM(reqs.req_qty) AS tot_req_qty
, CASE
WHEN reqs.req_date < sysdate
THEN 'Past Due'
ELSE To_Char(reqs.req_date,'MON-yyyy')
END AS month_reqd
FROM reqs
GROUP BY reqs.part_no
, CASE
WHEN reqs.req_date < sysdate
THEN 'Past Due'
ELSE To_Char(reqs.req_date,'MON-yyyy')
END
) m3 --for month 3
WHERE part.part_no = pd.part_no
AND pd.part_no = m1.part_no
AND m1.part_no = m2.part_no
AND m2.part_no = m3.part_no
AND pd.month_reqd = 'Past Due'
AND m1.month_reqd = To_Char(Add_Months(sysdate,1),'MON-yyyy')
AND m2.month_reqd = To_Char(Add_Months(sysdate,2),'MON-yyyy')
AND m3.month_reqd = To_Char(Add_Months(sysdate,3),'MON-yyyy')
ORDER BY part.part_noThe sample query above only gets 3 months worth of my tot_req_qty for each part number, which equals 3 (+1 for past due) copies of the subquery. This is how this query is "trimmed down" from my actual query; in my real query, I need to include at least 6 months (up to 12 months) of my tot_req_qty for each part number--which means 6-12 (+1) copies of the subquery...ick. I just can't imagine that being an efficient way to get this done.
Here's a table of the results I expect to get from my sample query:
PART_NO PART_DESC QTY_INSTOCK QTY_PAST_DUE QTY_THIS_MONTH QTY_NEXT_MONTH QTY_MONTH_3
part1 description 1 here 5 8 10 24 0
part2 description 2 here 10 40 0 0 0
part3 description 3 here 0 0 22 0 12Is there anything I can do differently here?
Thanks!!
Edited by: user11033437 on Feb 4, 2010 11:53 AM Fixed a typo
Edited by: user11033437 on Feb 4, 2010 12:08 PM Fixed another typoHi,
Instead of doing self-joins, you can pivot one result set.
Since it's just one result set, you can use an in-line view for it:
SELECT part.part_no
, part.part_desc
, part.qty_instock
, SUM ( CASE WHEN m.month_reqd = 'Past Due'
THEN m.tot_req_qty
ELSE 0
END
) AS qty_past_due
, SUM ( CASE WHEN m.month_reqd = To_Char(sysdate,'MON-yyyy')
THEN m.tot_req_qty
ELSE 0
END
) AS qty_this_month
, SUM ( CASE WHEN m.month_reqd = To_Char(Add_Months(sysdate, 1),'MON-yyyy')
THEN m.tot_req_qty
ELSE 0
END
) AS qty_next_month
, SUM ( CASE WHEN m.month_reqd = To_Char(Add_Months(sysdate, 2),'MON-yyyy')
THEN m.tot_req_qty
ELSE 0
END
) AS qty_month_3
FROM part
, ( -- Begin in-line view m
SELECT part_no
, SUM (req_qty) AS tot_req_qty
, month_reqd
FROM ( -- Begin in-line view rd
SELECT part_no
, req_qty
, CASE
WHEN req_date < sysdate
THEN 'Past Due'
ELSE To_Char(req_date,'MON-yyyy')
END AS month_reqd
FROM reqs
WHERE req_date < TRUNC ( ADD_MONTHS (SYSDATE, 3)
, 'MONTH'
) rd -- End in-line view rd
GROUP BY part_no
, month_reqd
) m -- End in-line view m
WHERE part.part_no = m.part_no
GROUP BY part.part_no
, part.part_desc
, part.qty_instock
ORDER BY part.part_no
;Notice I used a nested in-line view to compute month_reqd, rather than repeat the CASE expression. That's independent of the pivot: you can do either one with or without the other.
Thanks for posting the CREATE TABLE and INSERT statements! -
Need information on this Query
Hi guys,
can someone explain how this query works indetail.
SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
Advance thanks for your help.
Kadiyala
Edited by: user10223931 on Mar 4, 2009 8:17 PMHi,
SELECT DISTINCT (a.sal),(SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal) FROM EMP A order by 2 descI hope this will help you.
The query will rank the records as per salary amount. and you will get the salary amount of the specified rank. -
Select distinct(a.esal) from employee1 a where &N = (select count(distinct(b.esal)) from employee1 b where a.esal<=b.esal);
this is the query to find Nth largest & Nth smallest value from the table employee1....but, i am unable to understand how this query works ....plz..anybody can explain this query step by step with example....plzHi,
Welcome to the forum!
The first step in understanding any code is to format it so you can easily see what is a sub-query, what the major clauses of each sub-query are, and things like that.
For example:
Select distinct (a.esal)
from employee1 a
where &N = ( select count (distinct (b.esal))
from employee1 b
where a.esal <= b.esal
);The only thing I have added to the code you posted was whitespace: newlines, tabs and spaces.
Now it's easy to see that you're doing a query with a scalar sub-query in the WHERE clause.
It usually makes sense to read complicated queries from the inside out, that is, start with the deepest nested sub-query.
In this example, that means:
select count (distinct (b.esal))
from employee1 b
where a.esal <= b.esalWhat does this query do? Unfortunately, it references something (b.esal) from the super-query, so you can't run it by itself, to see what it does. Let's replace that reference with some hard-coded value, just for now, and run it:
select count (distinct (b.esal))
from employee1 b
--where a.esal <= b.esal -- This is the original WHERE clause
where a.esal <= 1000 -- For testing only
;Experiment with this for a while, and compare it to the values in the employee1 table (or a small test table that resembles employee1). Try different numbers in place of 1000.
You'll see that the query is counting how many different salaries are lower than, or equal to, a given salary (1000 in the example above).
When you understand the sub-query, look at the original query again.
It is testing to see if exactly &N different esals are lower than or equal to the esal on each row, and displaying that esal if it is. (&N is a substitution variable. If you haven't already defined a value for it, SQL*Plus will ask you for a value when you run the query.)
In other words, it is finding the N-th lowest value of esal. -
In ST03 , how can i see the Query name, user id,how many times executed the
HI Experts,
In ST03 , how can i see the Query name, user id,how many times executed the query.
these details how do i get from the above transaction.
EX:-if there is one report name X,I want to know how many users had executed X report today,weekly,monthly.
ex:-query userid total number of execution
sales order 0000555 5 times
custmer 05855 2 times
fast reply will be appreciated,Hi,
Look here:
http://help.sap.com/saphelp_nw04/helpdata/en/3b/54df4204892a78e10000000a155106/frameset.htm
Also check these:
http://help.sap.com/saphelp_nw2004s/helpdata/en/2d/b8be3befaefc75e10000000a114084/content.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/25/ece73a39e74d27e10000000a114084/frameset.htm
Hope this helps..
Bye
Dinesh -
How can I execute a query from a BSP application?
How can I execute a query from a BSP application?
I´m trying to execute a Query from intranet. I´ve been looking for examples, but the templates I´ve found doesn´t help me.
does anybody has an example?
Thanks.Hi
Have you designed the BSP application ?
design it first with one page
page will have layout and Event handlers
Design the layout with the fields
in the event handler there are events
in the event On Initiailization or ON inputprocessing write the select query similar to what we write in routine ABAp and fetch the data into ITAB and that has to be passed to the Layout
see the doc
BSP
To learn how to create Web applications with Business Server Pages, you can work through the simple tutorials that build on each other. You should be able to run through all of the steps described here in your own system.
If you want to develop Web applications with BSPs, your system must meet the following requirements: Prerequisites for Creating Web Applications.
The following tutorials are available:
· First Tutorial: First Steps with Business Server Pages
· Second tutorial: A Small BSP Application and A Small BSP Application with HTMLB
· Third tutorial: Our First Online Bookshop
· Fourth tutorial: Further Developing the Bookshop
· A small Tutorial is also available for your first steps with the Model View Controller design pattern.
· For a more complex MVC tutorial based on the third tutorial, see: Our Little Online Bookshop Using MVC and HTMLB
When creating BSP applications, note the browser dependencies described in Note 598860.
steps:
1) start the transaction RZ10.
2) now u u have to select Profile name, so select the INSTANCE Profile from the list of options given with the Profile parameter list.U may find multiple instance profile in the list, so select the profile in which ur server name is given.
3) u will also find three options in the same window.
Administrator data, Basic Maintenance, and Extended Maintenance. So select the last one from that.
4) Now click on change button.
5) here u will find parameter icm/host_name_full, so now set it as FQDN.
6) Now copy ur settings with new version number.
7) Activate that version.
8) And now please restart ur WAS.
So this will set ur FQDN, and also don't forget to login using Admin User.
Now u also check for following service are active in your ICF setting or not,( just start transaction code SICF)
/default_host/sap/bc/bsp/sap
/default_host/sap/bc/bsp/sap/system
/default_host/sap/bc/bsp/sap/public/bc
/def ault_host/sap/public/bc
/default_host/sap/public/bc/ur
/default_host/sap/public/bsp/sap/public
/default_host/sap/public/bsp/sap/public/bc
/defaul t_host/sap/public/bsp/sap/system
/default_host/sap/public/bsp/sap/htmlb
if not then activate all.
check this link
Read this weblog...
/people/brian.mckellar/blog/2003/09/25/bsp-in-depth-fully-qualified-domain-names
http://www.thespot4sap.com/articles/SAP_WAS_Creating_BSP_Apps.asp
it consists of screen shots also
Check it.
http://help.sap.com/saphelp_nw04/helpdata/en/c8/101c3a1cf1c54be10000000a114084/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/e9/bb153aab4a0c0ee10000000a114084/frameset.htm
Regards
Anji -
Please help me how to improve the performance of this query further.
Hi All,
Please help me how to improve the performance of this query further.
Thanks.Hi,
this is not your first SQL tuning request in this community -- you really should learn how to obtain performance diagnostics.
The information you posted is not nearly enough to even start troubleshooting the query -- you haven't specified elapsed time, I/O, or the actual number of rows the query returns.
The only piece of information we have is saying that your query executes within a second. If we believe this, then your query doesn't need tuning. If we don't, then we throw it away
and we're left with nothing.
Start by reading this blog post: Kyle Hailey &raquo; Power of DISPLAY_CURSOR
and applying this knowledge to your case.
Best regards,
Nikolay -
How i can execute the sql query in java code
I already have sql query in jave plateform i need to execute this code how i can do that. i have unix env and with oracle database. should i just run this query in my sqlplus. this file has extention .java. thanks
you can create a project in JDeveloper add the java file to it, add the Oracle JDBC library to the project properties and then hit the run button.
-
How to Improve perfomance of this query
Hi,
Please help me to improve this query performance. Objective of this query is to find out individual count who order the product in last two year and create a matrix with time period
Challenge is Both the table having more than 600 million record so it is taking to much time to execute
SELECT count(unique b.individual_id),
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955'))>= SYSDATE - 45 THEN 1 ELSE 0 END )) AS one_month ,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955'))>= SYSDATE - 105 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 45 THEN 1 ELSE 0 END )) AS Three_month,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 195 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 105 THEN 1 ELSE 0 END )) AS six_month,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 380 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 195 THEN 1 ELSE 0 END )) AS one_year,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 745 and NVL(ORDER_DT,TO_DATE('05-MAY-1955'))<= SYSDATE - 380 THEN 1 ELSE 0 END )) AS two_year
from ORDER b, address a
where b.individual_id = a.individual_id
and a.COUNTRY_CD ='US'
group by a.COUNTRY_CD ;
Thanks
Neeraj
Edited by: user4522368 on Aug 17, 2010 12:10 AMuser4522368 wrote:
Hi,
Please help me to improve this query performance. Objective of this query is to find out individual count who order the product in last two year and create a matrix with time period
Challenge is Both the table having more than 600 million record so it is taking to much time to execute Dombrooks has provided you with an excellent response.
In addition, you should mention how much time the query is currently taking and how much do you expect it to take, what is your database version etc.
One of the most important thing is to post your SQLs and EXPLAIN PLAN outcomes in readable format. You can do this by wrapping it within \ and \ tags.
Now, based on the limited details that you have provided, following are my questions/observations:
a) You claim that both tables have more than 600 million rows but your plan shows that optimizer is expecting to find only 46 million rows in ORDER table. You may want to confirm if statistics on both the tables are correct.
b) Your plan appears to suggest that the UNIQUE is not affecting the query results. Based on your knowledge of your data, do you need the COUNT(UNIQUE individual_id) or can it be just COUNT(individual_id)?
c) Finally, if you are interested in only last two years of data, you should probably have a WHERE predicate on your ORDER table which filters data based on ORDER_DT. Something like following:
SELECT count(unique b.individual_id),
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955'))>= SYSDATE - 45 THEN 1 ELSE 0 END )) AS one_month ,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955'))>= SYSDATE - 105 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 45 THEN 1 ELSE 0 END )) AS Three_month,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 195 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 105 THEN 1 ELSE 0 END )) AS six_month,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 380 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 195 THEN 1 ELSE 0 END )) AS one_year,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 745 and NVL(ORDER_DT,TO_DATE('05-MAY-1955'))<= SYSDATE - 380 THEN 1 ELSE 0 END )) AS two_year
from ORDER b, address a
where b.individual_id = a.individual_id
and a.COUNTRY_CD ='US'
and b.ORDER_DT <= (SYSDATE - 380)
group by a.COUNTRY_CD ; -
How Can i add "DateDiff(day, T0.DueDate" as a column in this query?
How Can i add "DateDiff(day, T0.DueDate" as a column in this query?
SELECT T1.CardCode, T1.CardName, T1.CreditLine, T0.RefDate, T0.Ref1 'Document Number',
CASE WHEN T0.TransType=13 THEN 'Invoice'
WHEN T0.TransType=14 THEN 'Credit Note'
WHEN T0.TransType=30 THEN 'Journal'
WHEN T0.TransType=24 THEN 'Receipt'
END AS 'Document Type',
T0.DueDate, (T0.Debit- T0.Credit) 'Balance'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')<=-1),0) 'Future'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=0 and DateDiff(day, T0.DueDate,'[%1]')<=30),0) 'Current'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>30 and DateDiff(day, T0.DueDate,'[%1]')<=60),0) '31-60 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>60 and DateDiff(day, T0.DueDate,'[%1]')<=90),0) '61-90 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>90 and DateDiff(day, T0.DueDate,'[%1]')<=120),0) '91-120 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,'[%1]')>=121),0) '121+ Days'
FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
WHERE (T0.MthDate IS NULL OR T0.MthDate > [%1]) AND T0.RefDate <= [%1] AND T1.CardType = 'C'
ORDER BY T1.CardCode, T0.DueDate, T0.Ref1Hi,
As you mentioned not possible to assign the dynamic column in the query.
will give you example for generate a dynamic column name in SQL query, using this example you can achieve your requirement.
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT distinct ',' + QUOTENAME(C.Name)
from [History]
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT [Date],' + @cols +'
from
select [Date], Name, Value
from [History]
) x
pivot
max(value)
for Name in (' + @cols + ')
) p '
execute(@query)
Maybe you are looking for
-
How to I use Microsoft Word to create or edit documents on my ipad2?
I have a PC laptop, an ipad2 and iphone 4s. I would like to do school work on my ipad2. How to I create documents with microsoft word on my ipad? Or if I have an assignment saved as a word.doc on my pc, how can I edit it or save it on my ipad? Thanks
-
Item Category Determination for sales document- Item USAGE
Hi dear all. I read already the discussions held around this subject, as I'm facing a similar problem for which I cannot find a solution. I have the need to set up a ItCat determination for sales order ZPD. The proposed ItCat must be <b>ZPDW</b>. How
-
HELP I HAVE A LENOVO DESKTOP WITH WIRELESS CONNECTION TO MY HP PRINTER. I HAVE A LENOVO DESKTOP WITH WIRELESS ROUTER FOR INTERNET. BOTH ACTIONS CONTINUOUSLY FAILED AT 100% OF THE TIME!!! I HARDWIRED MY HP PRINTER ... AND ALL PROBLEMS WERE RESOLVED!!!
-
How to add multiple tasks to the worklist view?
Hi, We are creating a view based on our BPM process and we are using OBPM 11.1.1.4. We do have 2 human workflow tasks in the process. While creating views in the worklist we are able to add only one task is there a way to add multiple tasks to one vi
-
Install 9.0.2.2 patchset
i am installing the OID 9.0.2.2 patchset (2682125) and the instructions say to unzip OID9022.ZIP in the ORACLE_HOME. however i cannot find the OID9022.ZIP file anywhere. Can someone please tell me where to locate this file. it was not in the p2682125