Query--please help
Hello Forum Members,
Can you please help me out:
SQL> select * from quarter_test4;
QUARTER CONFIG REP_DATE
Q1-2007 10 12-JAN-07
Q2-2007 10 21-APR-07
Q3-2007 870 14-AUG-07
Q4-2007 50 15-NOV-07
Q1-2008 60 02-JAN-09
Q4-2006 160 02-DEC-06
I want the following out put:
Please note that the future quarters should have current quarter sum(config).Please note that The current table
does not hold future quarters.I have to genarate query on which a report is based.
My Query:
SELECT quarter,
CASE
WHEN qtr > TRUNC(SYSDATE, 'q')
THEN LAST_VALUE(sum_config IGNORE NULLS) OVER(ORDER BY qtr)
ELSE sum_config
END sum_config
FROM (SELECT qtr, q.qtrstr quarter, SUM(qt.config) sum_config
FROM (SELECT 'Q' || TO_CHAR(qtr, 'q-yyyy') qtrstr, qtr
FROM (SELECT ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'q'), -13), 3 *(LEVEL - 1)) qtr
FROM DUAL
CONNECT BY LEVEL <= 9)
ORDER BY qtr) q,
quarter_test4 qt
WHERE qt.quarter(+) = q.qtrstr
GROUP BY qtr, q.qtrstr)
ORDER BY qtr;
Correct Output Generated:
QUARTER SUM_CONFIG
Q4-2006 160
Q1-2007 10
Q2-2007 10
Q3-2007 870
Q4-2007 50
Q1-2008 60
Q2-2008 60
Q3-2008 60
Q4-2008 60
====================================================================================================================================
New Requirement:Product column has been added.
SQL> select * from quarter_test3;
QUARTER CONFIG REP_DATE PRODUCT
Q1-2007 10 12-JAN-07 P1
Q2-2007 10 21-APR-07 P1
Q3-2007 870 14-AUG-07 P1
Q4-2007 50 15-NOV-07 P1
Q1-2008 60 02-JAN-09 P1
Q4-2006 160 02-DEC-06 P1
Q4-2006 997 02-DEC-06 P2
Q4-2007 60 14-NOV-07 P2
Q3-2007 970 14-NOV-07 P2
Q2-2007 20 21-APR-07 P2
Q1-2007 20 12-JAN-07 P2
QUARTER CONFIG REP_DATE PRODUCT
Q1-2008 70 12-JAN-08 P2
Expected Output:
Q4-2006 160 P1
Q1-2007 10 P1
Q2-2007 10 P1
Q3-2007 870 P1
Q4-2007 50 P1
Q1-2008 60 P1
Q2-2008 60 P1
Q3-2008 60 P1
Q4-2008 60 P1
Q4-2006 260 P2
Q1-2007 20 P2
Q2-2007 20 P2
Q3-2007 970 P2
Q4-2007 60 P2
Q1-2008 70 P2
Q2-2008 70 P2
Q3-2008 70 P2
Q4-2008 70 P2
My Query:
SELECT quarter,product,
CASE
WHEN qtr > TRUNC(SYSDATE, 'q')
THEN LAST_VALUE(sum_config IGNORE NULLS) OVER(ORDER BY qtr)
ELSE sum_config
END sum_config
FROM (SELECT qtr, q.qtrstr quarter,product, SUM(qt.config) sum_config
FROM (SELECT 'Q' || TO_CHAR(qtr, 'q-yyyy') qtrstr, qtr
FROM (SELECT ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'q'), -13), 3 *(LEVEL - 1)) qtr
FROM DUAL
CONNECT BY LEVEL <= 9)
ORDER BY qtr) q,
quarter_test3 qt
WHERE qt.quarter(+) = q.qtrstr
GROUP BY qtr,product, q.qtrstr)
ORDER BY substr(qtr,-4),substr(QTR,2,1)
Output:
QUARTER PRODUCT SUM_CONFIG
Q4-2006 P1 160
Q4-2006 P2 997
Q4-2007 P1 50
Q4-2007 P2 60
Q4-2008 70
Q2-2007 P1 10
Q2-2007 P2 20
Q2-2008 70
Q3-2007 P1 870
Q3-2007 P2 970
Q3-2008 70
QUARTER PRODUCT SUM_CONFIG
Q1-2007 P1 10
Q1-2007 P2 20
Q1-2008 P1 70
Q1-2008 P2 70
The query had not generated q2-2008,q3-2008,q4-2008 values [60]for P1...it had only generated q2-2008,q3-2008,q4-2008 values[70] for product P2.
Can you please advise me.
You can make up the data using the model clause:
SQL> create table quarter_test3 (quarter, config, product)
2 as
3 select 'Q1-2007', 10, 'P1' from dual union all
4 select 'Q2-2007', 10, 'P1' from dual union all
5 select 'Q3-2007', 870, 'P1' from dual union all
6 select 'Q4-2007', 50, 'P1' from dual union all
7 select 'Q1-2008', 60, 'P1' from dual union all
8 select 'Q4-2006', 160, 'P1' from dual union all
9 select 'Q4-2006', 997, 'P2' from dual union all
10 select 'Q1-2007', 60, 'P2' from dual union all
11 select 'Q2-2007', 970, 'P2' from dual union all
12 select 'Q3-2007', 20, 'P2' from dual union all
13 select 'Q4-2007', 20, 'P2' from dual union all
14 select 'Q1-2008', 70, 'P2' from dual
15 /
Tabel is aangemaakt.
SQL> select 'Q' || to_char(mod(q,4) + 1) || '-' || to_char(trunc(q/4)) quarter
2 , config
3 , product
4 from quarter_test3
5 model
6 partition by (product)
7 dimension by (to_number(substr(quarter,4))*4 + to_number(substr(quarter,2,1)) - 1 q)
8 measures (config)
9 rules
10 ( config[for q from 2006*4 + 3 to 2008*4 + 3 increment 1]
11 = nvl(config[cv()],config[cv()-1])
12 )
13 order by product
14 , q
15 /
QUARTER CONFIG PR
Q4-2006 160 P1
Q1-2007 10 P1
Q2-2007 10 P1
Q3-2007 870 P1
Q4-2007 50 P1
Q1-2008 60 P1
Q2-2008 60 P1
Q3-2008 60 P1
Q4-2008 60 P1
Q4-2006 997 P2
Q1-2007 60 P2
Q2-2007 970 P2
Q3-2007 20 P2
Q4-2007 20 P2
Q1-2008 70 P2
Q2-2008 70 P2
Q3-2008 70 P2
Q4-2008 70 P2
18 rijen zijn geselecteerd.Regards,
Rob.
Similar Messages
-
How to improve the performance of the attached query, Please help
Hi,
How to improve performance of the below query, Please help. also attached explain plan -
SELECT Camp.Id,
rCam.AccountKey,
Camp.Id,
CamBilling.Cpm,
CamBilling.Cpc,
CamBilling.FlatRate,
Camp.CampaignKey,
Camp.AccountKey,
CamBilling.billoncontractedamount,
(SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
rCam.AccountKey as AccountKey
FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
WHERE Camp.AccountKey = rCam.AccountKey
AND Camp.AvCampaignKey = rCam.AvCampaignKey
AND Camp.AccountKey = CamBilling.AccountKey
AND Camp.CampaignKey = CamBilling.CampaignKey
AND rCam.AccountKey = xSite.AccountKey
AND rCam.AvSiteKey = xSite.AvSiteKey
AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
to_date('01-01-2011', 'DD-MM-YYYY')
GROUP By rCam.AccountKey,
Camp.Id,
CamBilling.Cpm,
CamBilling.Cpc,
CamBilling.FlatRate,
Camp.CampaignKey,
Camp.AccountKey,
CamBilling.billoncontractedamount
Explain Plan :-
Description Object_owner Object_name Cost Cardinality Bytes
SELECT STATEMENT, GOAL = ALL_ROWS 14 1 13
SORT AGGREGATE 1 13
VIEW GEMINI_REPORTING 14 1 13
HASH GROUP BY 14 1 103
NESTED LOOPS 13 1 103
HASH JOIN 12 1 85
TABLE ACCESS BY INDEX ROWID GEMINI_REPORTING RCAMSIT 2 4 100
NESTED LOOPS 9 5 325
HASH JOIN 7 1 40
SORT UNIQUE 2 1 18
TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY SITE 2 1 18
INDEX RANGE SCAN GEMINI_PRIMARY SITE_I0 1 1
TABLE ACCESS FULL GEMINI_PRIMARY SITE 3 27 594
INDEX RANGE SCAN GEMINI_REPORTING RCAMSIT_I 1 1 5
TABLE ACCESS FULL GEMINI_PRIMARY CAMPAIGN 3 127 2540
TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY CAMBILLING 1 1 18
INDEX UNIQUE SCAN GEMINI_PRIMARY CAMBILLING_U1 0 1Hello,
This has really nothing to do with the Oracle Forms product.
Please, send the SQL or/and PL/SQL questions in the corresponding forums.
Francois -
PROBLEM WITH HIERARCHICAL QUERY - PLEASE HELP
I have got three tables :
CREATE TABLE FIRM
(FID INTEGER NOT NULL PRIMARY KEY,
FNAME VARCHAR(40),
FTYPE VARCHAR(3),
MASTERID INTEGER );
CREATE TABLE FACULTY
(FAID INTEGER NOT NULL PRIMARY KEY,
FANAME VARCHAR(40),
FATYPE VARCHAR(3),
MASTERID INTEGER );
CREATE TABLE EMPLOYEE
(EID INTEGER NOT NULL PRIMARY KEY,
ENAME VARCHAR(20),
ESURNAME VARCHAR(20),
EJOB VARCHAR(3),
MASTERID INTEGER );
This is a hierarchical tree(or is ment to be, I,m complete rookie ) . Firm can be the root or can be slave to another firm. Faculty can be slave to firm, or to another faculty. Employee can be slave to faculty or to another employee(e.g. boss). This connections are specified by MASTERIDs.
I need to write a procedure, which parameter would be node ID. It is meant to create a VIEW from this node as if it was a root (view of a subtree).
I tried CONNECT BY clause but it works only on one table at a time and I have here three tables.
I completely don,t know how to write it. Please help.create view hierarchy as
select id, master_id, name from table1
union all
select id, master_id, name from table2
union all
select id, master_id, name from table3
Then do your connect by query against hierarchy.
It will not work in 8i (connect by on views not allowed), so you will need to materialize the view.
Kirill -
How to make recursive query.Please help
Dear Experts:
I want to retrieve all employees located in a department in addition to all other employees located in the child's nodes of this department too.
Problem Details:
I have "Employees" table and "Departments" Table
The structure of Dept Table is:
ID primary key
parent_dept foreign key(id)
deptname varchar2
deptType varchar2
The Employee table structure is
ID primary key
dept_id foreign key(Department.id)
empName varchar2Sample data for departments
ID : 1
parent_dept : null
deptname: General Manager office
deptType : 'GM'
ID :=2
parent_dept : 1
deptname: Information tech.
deptType : 'DPT'
ID :=3
parent_dept : 2
deptname: Software Development
deptType : 'SECTION'Sample Data for employees
ID : 101
dept_id :1
empName King
ID : 102
dept_id :2
empName ALAN
ID : 103
dept_id :2
empName SAM
ID : 104
dept_id :3
empName JANEI want to create a query that accepts a parameter "p_department_id" and returns All employees on the following conditions
1- In case the parameter value is null , then retrieve All Employees "king - alan- sam-jane"
2- In Case the parameter value is 1 , then retrieve all the employees under department id =1 in addition to all the employees located under the children departments.
in this case it will be "king - alan- sam-jane"
3- In case parameter value is 2 , then return all the employees under department id =2 in addition to all the employees located under the children departments.
In this case it will be " alan- sam-jane"
4- In case parameter value is 3 , then return all the employees under department id =3 in addition to all the employees located under the children departments.
in this case it will be only "JANE"
In brief , If I pass any value to the parameter :p_department_id , I want to retrieve all employees located in this department in addition to other employees located in the child's nodes of this department id
I use oracle database 11g release 2
Please help me
Thanks
Edited by: ta**** on Apr 3, 2013 5:56 PM
Edited by: ta**** on Apr 3, 2013 5:58 PMSQL> variable p_department_id number
SQL> exec :p_department_id := null
PL/SQL procedure successfully completed.
SQL> with employees as (
2 select 101 id,1 dept_id,'King' empName from dual union all
3 select 102,2,'ALAN' from dual union all
4 select 103,2,'SAM' from dual union all
5 select 104,3,'JANE' from dual
6 ),
7 departments as (
8 select 1 id,null parent_dept,'General Manager office' deptname,'GM' deptType from dual union all
9 select 2,1,'Information tech.','DPT' from dual union all
10 select 3,2,'Software Development','SECTION' from dual
11 )
12 select *
13 from employees
14 where dept_id in (
15 select id
16 from departments
17 start with (
18 (
19 :p_department_id is null
20 and
21 parent_dept is null
22 )
23 or
24 id = :p_department_id
25 )
26 connect by parent_dept = prior id
27 )
28 /
ID DEPT_ID EMPN
101 1 King
102 2 ALAN
103 2 SAM
104 3 JANE
SQL> exec :p_department_id := 1
PL/SQL procedure successfully completed.
SQL> /
ID DEPT_ID EMPN
101 1 King
102 2 ALAN
103 2 SAM
104 3 JANE
SQL> exec :p_department_id := 2
PL/SQL procedure successfully completed.
SQL> /
ID DEPT_ID EMPN
102 2 ALAN
103 2 SAM
104 3 JANE
SQL> exec :p_department_id := 3
PL/SQL procedure successfully completed.
SQL> /
ID DEPT_ID EMPN
104 3 JANE
SQL> SY. -
Table1
QTE_ID SEQ_NO
1435177 2
1435177 5
1435177 7
1435177 8
1435177 12
1435177 14
Table2
QTE_ID SEQ_NO CMMT_CURR_AMT
1435177 1 98500
1435177 2 98500
1435177 3 0
1435177 4 98500
1435177 5 98500
1435177 7 98500
1435177 8 98500
1435177 11 59300
1435177 12 59300
1435177 14 59300
The result should be
QTE_ID SEQ_NO CMMT_CURR_AMT
1435177 2 0 (where 0 = cmmt_curr_amt of seq 2 - cmmt_curr_amt of seq 1 from table 2)
1435177 5 0 (where 0 = cmmt_curr_amt of seq 5 - cmmt_curr_amt of seq 4 from table 2)
1435177 7 0 (where 0 = cmmt_curr_amt of seq 7 - cmmt_curr_amt of seq 5 from table 2)
1435177 8 0 (where 0 = cmmt_curr_amt of seq 8 - cmmt_curr_amt of seq 7 from table 2)
1435177 12 0 (where 0 = cmmt_curr_amt of seq 12 - cmmt_curr_amt of seq 11 from table 2)
1435177 14 0 (where 0 = cmmt_curr_amt of seq 14 - cmmt_curr_amt of seq 12 from table 2)
I have to get the difference of cmmt_curr_amt from the table2 from seq 14 to seq 12 for seq14 in table 1.
Please help me in writing the query.
Thanks in advance.
SrinivasWITH table1 AS
(SELECT 1435177 qte_id, 2 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no
FROM dual
table2 AS
SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
FROM dual
SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
FROM
(SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
FROM table1 t1, table2 t2
WHERE t2.qte_id = t1.qte_id (+)
AND t2.seq_no = t1.seq_no(+)
ORDER BY 1,2
WHERE t1_seq_no IS NOT NULL
ORDER BY 1,2
QTE_ID T2_SEQ_NO DIFF
1435177 2 0
1435177 5 0
1435177 7 0
1435177 8 0
1435177 12 0
1435177 14 0 -
How to rewrite this query without sub query please help me
Hello All Good Evening,
Could you please help me with this query, how can i write this query without sub query, or how can write this query another ways
please help me
select planno, status1, count(*) Counts from
select a.ValetNO PlanNo ,
case
when JoinCode in ('00', '01', '02') then 'Actcess'
when JoinCode in ('20', '21', '22', '23','38', '39') then
'Secured' else 'Other' end Status1 ---, COUNT (*)
from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
--group by a.ValetNO
a group by planno, status1
order by 2
Thank you in Advance
MilanWhats your objective here? Sorry, am not able to understand the reason for this change.
Try the below:(Not tested)
;With cte
As
select a.ValetNO PlanNo ,
case
when JoinCode in ('00', '01', '02') then 'Actcess'
when JoinCode in ('20', '21', '22', '23','38', '39') then
'Secured' else 'Other' end Status1 ---, COUNT (*)
from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
select planno, status1, count(*) Counts from cte
a group by planno, status1
order by 2
Even below:
select a.ValetNO PlanNo ,
case
when JoinCode in ('00', '01', '02') then 'Actcess'
when JoinCode in ('20', '21', '22', '23','38', '39') then
'Secured' else 'Other' end Status1 , COUNT (1)
from dbo.ppt a(NOLOCK) left join dbo.acts b on a.P_ID = b.P_ID and a.ValetNO = b.ValetNO
Group by a.ValetNO ,
case
when JoinCode in ('00', '01', '02') then 'Actcess'
when JoinCode in ('20', '21', '22', '23','38', '39') then
'Secured' else 'Other' end -
Problem while designing query please help
Hi all,
I have to query to find No of open cases, No of closed cases,
Average of open cases, Average age of closed cases,
Maximum of closed cases for a particulat Current assigne(char).
my desired output is as follows.
CurAssigne Noofopencases Noofclosed cases Avgage(opencases) Max(open)
CurAssigne1 10 20 8 9
CurAssigne1 18 22 9 10
My cube is consists of.
4 Dimensions & 4 key figures
4Dimensions are listed below.
Business Partner{currentassigne, previousassigne,acmanager}
createdon{createdonmonth,createdonday,createdtime}
closedon{closedmonth,closedday,closedtime}
Status{Latest case status-(2 status are available for each case - open,close)}
above the objects between {} are chars.
4 keys are listed below.
no of cases.
age
first response time
research time.
Please help me to design this query friends..
It's very urgent friends please help me.Hi,
Please share your system configuration on which you are trying to install Ps CS6.
Regards,
Ashutosh
Ps Installer QE -
Passing parameter to a SQL query - Please help
Hi All,
I am new to JDBC. I have been trying to pass an external variable to an SQL Query.
The query is
String username1="le";
PreparedStatement pstmt = null;
pstmt = c.prepareStatement("select * from users where USER_NAME like '%?%'");
pstmt.setString(1, username1);
pstmt.executeQuery();
ResultSet rs = pstmt.getResultSet();
I am trying to retrieve values from the users table where the USER_NAME column value that is a String contains the supplied value username1.
I am using the question mark (?) character to pass the value from the variable username1. I am also using the '%' substitution character which matches for any number of characters. So, the above query should retrieve rows where the USER_NAME is something like "charles","leander","Elena" etc.( that contains "le")
I am getting the error:
SQLException: java.sql.SQLException: ORA-01006: bind variable does not exist
I changed the query to
PreparedStatement pstmt = null;
pstmt = c.prepareStatement("select * from users where USER_NAME like '% " + username1 + "%'");
//pstmt.setString(1, username1);
pstmt.executeQuery();
This time , it is not giving the error and retrieving properly.
But I want to use the original query and use the "pstmt.setString(1, username1); " . Is there any way of achieving this?
Please help.
Cheers,
charles_amhi,
try this...
String username1="%le%";
pstmt = c.prepareStatement("select * from users where USER_NAME like ?")
pstmt.setString(1,username1);
cheers,
rpk -
Hi experts,
what i want to do is write a single query which will show whether a employee
exits in the company or not.I have two tables emp and dept.There are as follows.
SQL> select * from emp;
NAME DEPTNO EMPNO
xxx 10 33036
YYY 12 2345
ZZZ 13 678
KKK 14 5678
RRR 15 7865
SQL> select * from dept;
DEPTNO LOCATION
10 AAA
11 BBB
12 CCC
13 DDD
what i want is it will select records from the emp table and find whether corrosponding
deptno really exists in the dept table.If the value is found in deptno column the dept table then it will set the value
Y other wise it will be N and all i have to do with the help of a single query.
expected result
name empno exists
xxx 33036 Y
YYY 2345 Y
ZZZ 678 Y
KKK 5678 N
RRR 7865 N
Please help.
Regards
RajatSELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N') EXIST
FROM EMP
ORDER BY 1
Demo
SQL> WITH EMP AS(
2 SELECT 'XXX' NAME , 10 DEPTNO ,33036 EMPNO FROM DUAL UNION
3 SELECT 'YYY', 12, 2345 FROM DUAL UNION
4 SELECT 'ZZZ', 13 ,678 FROM DUAL UNION
5 SELECT 'KKK', 14 ,5678 FROM DUAL UNION
6 SELECT 'RRR', 15 ,7865 FROM DUAL ),
7 DEPT AS(
8 SELECT 10 DEPTNO,'AAA' DNAME FROM DUAL UNION
9 SELECT 11 ,'BBB' FROM DUAL UNION
10 SELECT 12 ,'CCC' FROM DUAL UNION
11 SELECT 13 ,'DDD'FROM DUAL )
12 SELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N')
EXIST
13 FROM EMP
14 ORDER BY 1
15 /
EMPNO NAM EMPNO E
678 ZZZ 678 Y
2345 YYY 2345 Y
5678 KKK 5678 N
7865 RRR 7865 N
33036 XXX 33036 Y
SQL> Edited by: Salim Chelabi on Dec 7, 2008 4:15 AM -
Hi,
Currently we have a query (Created on Multicube - one is sales plan cube and another is Sales actuals).
When we run the query on a particular day (example: 7/10/2006), the report looks like as below:
Cal.Year/Month Sales plan Sales Actuals
Jan'06 310 305
Feb'06 280 277
Mar'06 310 309
Apr'06 300 300
MAy'06 310 305
June'06 300 305
July'06 310 90
The current report shows the whole month's Sales Plan (July'06 - 310) with Actual Sales for 9 days(for July'06 - 90). Whereas, We want to compare the sales Plan (first 9 days of the month) against the sales actuals for 9 days.
We do not have 0calday in both the cubes. Please help.
Thanks,David,
As rightly pointed out , you cannot get the plan value for 9 days if you do not have 0calday. However some things you can do...
1. Have a virtual KF which gets the number of days from the current calendar day ( system date ) to the first date of the month - this can be written with a simple exit since the first date is fixed.
2. calculate the plan value from that - pro rated plan value = plan value for month / number of days in month * number of days elapsed. If need be have the virtual KF return the ratio of number of days elapsed/number of days in the month
3. Now you can do the comparison assuming that the value of actuals will be till the current date and not beyond.
This is assuming that you can write a Virtual KF and the number of records is less enough to avoid any performance issues
Hope it helps..
Arun
Assign points if helpful
Message was edited by: Arun Varadarajan -
Pivot table query - PLEASE HELP
I have one requirement whichis similar like this.
I have following tables.
POSITIONS (one account holds multiple securities)
account_id security_id total
1 101 300
1 102 500
2 102 300
2 103 600
3 104 400
4 104 800
SECURITIES
security_id security_name country region
101 ABC USA NA
102 EFG USA NA
103 PQR GBR EUR
104 XYZ CANADA NA
I will get all the account numbers from front end application, for which I have to display output like this. For example I am getting accounts, 1,2,3 and 4 and have to display like columns at the end. I have to groupy by region and country.
REGION COUNTRY SECURITY_ID SECURITY_NAME 1 2 3 4
NA USA 101 ABC 300
102 EFG 500 300
COUNTRY TOTAL 800 300
CANADA 104 XYZ 400 800
REGION TOTAL 800 300 400 800
EUR GBR 103 PQR 600
COUNTRY TOTAL 600
REGION TOTAL 800 900 400 800
I am working on Oracle 9i Release 2 and front end is .net. Can anyone please help me out with a solution using a query or a stored proc. For Stored procedure, I should send refcurser as OUT parameter or any possible solution.
Thanks in advance.You could do the following:
In SQL
You can use the decode function and SUM over it.
Get the totals by region and country
select region,country, s.sec_id, sec_name,
sum(decode(acct_id,1,total,0)) a1,
sum(decode(acct_id,2,total,0)) a2,
sum(decode(acct_id,3,total,0)) a3,
sum(decode(acct_id,4,total,0)) a4
from positions p, securities s
where p.SEC_ID = s.SEC_ID
group by region,country, s.sec_id, sec_name
You can run similar sql to get totals by country or region separately ... just remove from select and group by clause the column name that you do not want to be displayed.
The limitation here is that you would need to write the decode statement for every account. Some programming may be needed here.
In PLSQL
create or replace procedure acct_sum (cr OUT sys_refcursor)
is
cursor c1 is
select distinct acct_id from positions order by 1 asc;
var1 varchar2(1000) := ' ';
var2 varchar2(1000);
begin
for i in c1 loop
var1 := var1 || ' sum(decode(acct_id, ' || i.acct_id || ', total,0) ),';
end loop;
var1 := substr(var1,1,length(var1)-1);
open cr for
'select region,country, s.sec_id, sec_name, ' || var1 ||
'from positions p, securities s
where p.SEC_ID = s.SEC_ID
group by region,country, s.sec_id, sec_name';
end acct_sum;
You may want to modify the code so pass in an array of accounts and loop through the content to get all the accounts.
Hope this helps
Shakti
http://www.impact-sol.com
Developers of Guggi Oracle - Tool for DBAs and Developers -
Approval process QUERY - Please help guys....
Hello Experts,
I have found some threads in this subject but non of them seem to work for me.
My need is :
when my employee tries to turn an order into an Invoice witch its card is set to groupname of 'over seas clients' the invoice will not be produced and the approval pop up will show.
this is what i tryed :
SELECT distinct 'true' FROM OINV T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode INNER JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode AND T2.GroupName 'Over seas clients' where T0.CardCode = $[$4.0.0]
nothing happens and the approval pop up never shows up.
Could someone Please help me with this query?
Thanks alot
D.medI thin approval process work like in this manner.
when you add any SO for particular condition matches then approval pop up will come, and then that SO gone to Approval. After approval user can able to make Invoice.
Hence i think in your case you need to made a query in SO that when the particular groupname is added then aproval should pop up.
Else you can kept the approval process in AR Invoice that if particular groupname is added then pop up.
For Approval process you need to select this query in Approval Template. -
Cluster bar chart- sql query please help-
Hi,
I am trying to create cluster bar chart and am stumped with this sql query.Any help is appreciated.
Here is my table
city region issue value
c1 north i1 y
c1 north i2 y
c2 north i1 n
c2 north i2 y
c3 south i1 y
c3 south i2 n
c4 east i1 n
c4 east i2 n
The bar chart will have 3 series, north south and east.
And labels will be i1 and i2. value will be number of times this issue was encountered(y) in this region.
How can I get something like this from the above table-
region issue count(yes)
north i1 1
north i2 2
south i1 1
south i2 0
east i1 0
east i2 0
thanksWITH table1 AS
(SELECT 1435177 qte_id, 2 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no
FROM dual
table2 AS
SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
FROM dual
SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
FROM
(SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
FROM table1 t1, table2 t2
WHERE t2.qte_id = t1.qte_id (+)
AND t2.seq_no = t1.seq_no(+)
ORDER BY 1,2
WHERE t1_seq_no IS NOT NULL
ORDER BY 1,2
QTE_ID T2_SEQ_NO DIFF
1435177 2 0
1435177 5 0
1435177 7 0
1435177 8 0
1435177 12 0
1435177 14 0 -
A very basic query, Please help.
Hi all,
I am very new to java and need your help in getting rid of this error. Please help.
I have written two java files. packageTest.java and callPackageTest.java. Following is the code:
// packageTest.java
package aaa.bbb.ccc;
public class packageTest
public packageTest()
System.out.println("This is from inside package test constructor");
public static void main(String[] args)
packageTest obj1 = new packageTest();
System.out.println("Hello World!");
//callPackageTest.java
import aaa.bbb.ccc.*; // there is a star at the end. Seems to get removed by the forum every time.
public class callPackageTest
public static void main(String[] args)
packageTest obj1 = new packageTest();
System.out.println("Hello World!");
Now when I compile packageTest.java with the following command:
javac -d . packageTest.java
I get correct class file created in correct directory, i.e. aaa/bbb/ccc/packageTest.class.
But now when I try to compile the java file callPackageTest.java with the following command:
javac -cp . callPackageTest.java
I get the following error message:
class file contains wrong class.
Please remove or make sure it appears in the correct subdirectory of the classpath
I also observed that when I put the complete class name in the import statement in the file callPackageTest.java ( import aaa.bbb.ccc.packageTest; ) then there is no error. But I expect the same to be done when I write import aaa.bbb.ccc. * ( an star at the end)
Where is the mistake ? Please help.
Thanks in advance.
Sinha
Edited by: sinha_java on May 26, 2010 10:50 PM
Edited by: sinha_java on May 26, 2010 10:52 PMThanks guys for all the information about how to post and other forum related stuff. So here goes the formatted code.
I have written two java files. packageTest.java and callPackageTest.java. Following is the code:
// packageTest.java
package aaa.bbb.ccc;
public class packageTest
public packageTest()
System.out.println("This is from inside package test constructor");
public static void main(String[] args)
packageTest obj1 = new packageTest();
System.out.println("Hello World!");
//callPackageTest.java
import aaa.bbb.ccc.*;
public class callPackageTest
public static void main(String[] args)
packageTest obj1 = new packageTest();
System.out.println("Hello World!");
Now when I compile packageTest.java with the following command:
javac -d . packageTest.javaI get correct class file created in correct directory, i.e. aaa/bbb/ccc/packageTest.class.
But now when I try to compile the java file callPackageTest.java with the following command:
javac -cp . callPackageTest.javaI get the following error message:
class file contains wrong class.
Please remove or make sure it appears in the correct subdirectory of the classpath
I also observed that when I put the complete class name in the import statement in the file callPackageTest.java ( import aaa.bbb.ccc.packageTest; ) then there is no error. But I expect the same to be done when I write import aaa.bbb.ccc.*
Where is the mistake ? -
SQL I need help with this query Please help
List the names of all the products whose weight unit measure is “Gram”. Order the list by product name. Do not use JOINS, but use the IN clause with a sub-query.
select Name
from UnitMeasure
where Name= 'Gram'
order by Name
I did this, but it seem that the requirement is different.As a guess:
Select Name from Product
where UnitMeasure in (Select Name from unitmeasure where name = 'Gram')
Andy Tauber
Data Architect
The Vancouver Clinic
Website | LinkedIn
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click
"Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.
Maybe you are looking for
-
On a tabbed panel, I am trying to create a form, but...
On a tabbed panel I am trying to create a form, but I am having a couple of issues. The coding on my form is yellow - I can't figure out what is wrong. Also, I can't see the tab on the browser, only in live view. I haven't loaded it to my site as I h
-
Hi all, I have a requirement wherein i need to create a infotype. In this infotype if the Anzhl value of absence quota type is reduced the relavent quota types which are linked to it should also get reduced. Actually when a leave is approved, the qu
-
My Iphone 4s keeps locking itself, as if I pressed the "lock button"
I bought a new Iphone 4s, Since the minute I activated it, it randomally turns itself on and off, locking the screen etc. Sometimes it stopps for several hours, and then starts to lock again every five seconds. If i turn it off, it turns back on by i
-
How to get the Network Users Are Available Dot to Show up Automatically On Mac OS X Login Screen
i am wondering how you make it so that the little tiny green dot with network users are avalble appere on start up automaticly with out having to do a bunch of crap dont know if this matters but i am using an emac (Not Sure What Modle) With mac OS X
-
Updating information using sqlplus
I cannot figure out why my code will not update my database. Using sqlplus. I can type it into the database myself, but I cannot seem to pass the information through my jsp program String type = request.getParameter("studentSelection"); String studen