Help needed in building a query
Hello,
I am using Oracle DB 11g.
I want to write a query which gives the next and previous rows for a table, depending upon another column A.
That A column value is from 1 to 10.
If i select column value as 3 then i should get data for column value 2 and 4.
And also if i select 10 i should get data for column value 9 and 1.
How to write this query?
Thanks
Edited by: user13305573 on Dec 9, 2010 4:00 AM
Code with some sample data and output
SQL>VARIABLE your_input NUMBER
SQL>exec :your_input := 5
PL/SQL procedure successfully completed.
SQL>
SQL>WITH t
2 AS
3 ( SELECT 1 a, 'A1' name FROM DUAL UNION ALL
4 SELECT 2 a, 'A2' name FROM DUAL UNION ALL
5 SELECT 3 a, 'A3' name FROM DUAL UNION ALL
6 SELECT 4 a, 'A4' name FROM DUAL UNION ALL
7 SELECT 5 a, 'A5' name FROM DUAL UNION ALL
8 SELECT 6 a, 'A6' name FROM DUAL UNION ALL
9 SELECT 7 a, 'A7' name FROM DUAL UNION ALL
10 SELECT 8 a, 'A8' name FROM DUAL UNION ALL
11 SELECT 9 a, 'A9' name FROM DUAL UNION ALL
12 SELECT 10 a, 'A10' name FROM DUAL
13 )
14 SELECT *
15 FROM t
16 WHERE a = :your_input - 1
17 OR a = ( SELECT CASE WHEN :your_input = MAX(a)
18 THEN MAX(a) - :your_input + 1
19 ELSE :your_input + 1
20 END
21 FROM t
22 );
A NAM
4 A4
6 A6
SQL>
SQL>
SQL>exec :your_input := 10
PL/SQL procedure successfully completed.
SQL>
SQL>WITH t
2 AS
3 ( SELECT 1 a, 'A1' name FROM DUAL UNION ALL
4 SELECT 2 a, 'A2' name FROM DUAL UNION ALL
5 SELECT 3 a, 'A3' name FROM DUAL UNION ALL
6 SELECT 4 a, 'A4' name FROM DUAL UNION ALL
7 SELECT 5 a, 'A5' name FROM DUAL UNION ALL
8 SELECT 6 a, 'A6' name FROM DUAL UNION ALL
9 SELECT 7 a, 'A7' name FROM DUAL UNION ALL
10 SELECT 8 a, 'A8' name FROM DUAL UNION ALL
11 SELECT 9 a, 'A9' name FROM DUAL UNION ALL
12 SELECT 10 a, 'A10' name FROM DUAL
13 )
14 SELECT *
15 FROM t
16 WHERE a = :your_input - 1
17 OR a = ( SELECT CASE WHEN :your_input = MAX(a)
18 THEN MAX(a) - :your_input + 1
19 ELSE :your_input + 1
20 END
21 FROM t
22 );
A NAM
1 A1
9 A9Regards
Arun
Similar Messages
-
Tab1
Parent Child sa l
P1 A1 4000
A1 A 1000
A1 B 4000
A X 1000
A Y 2000
B X1 1000
B X2 3000I need to build a query that will retrieve the value for each child as the sum of the salaries of all its child in a single query.
That is
For Sal P1 = Sal A1 + all child of A1 and its child
For A1 = Sal A1 + all child of A1 and its child ( A+B+X+Y+X1+X2)
Like it should sho all the records with the count .. please helpThis is not so simple since it is not really clear in your data set whether the sal belongs to the parent or to the child. I assume it's the salary of the child, in which case the salary of P1 is missing. The best option is to fix the data model and have two tables: one containing the element and sal, and another table containing just the relationships. To fix this issue I introduced a dummy record for P1 and salary 0.
SQL> with t2 as
2 ( select connect_by_root(child) cbr
3 , sal
4 from (select * from t union all select null,'P1',0 from dual)
5 connect by parent = prior child
6 )
7 select cbr child
8 , sum(sal)
9 from t2
10 group by cbr
11 /
CHILD SUM(SAL)
X1 1000
A1 16000
X2 3000
P1 16000
Y 2000
X 1000
A 4000
B 8000
8 rows selected.Regards,
Rob. -
Help needed to optimize the query
Help needed to optimize the query:
The requirement is to select the record with max eff_date from HIST_TBL and that max eff_date should be > = '01-Jan-2007'.
This is having high cost and taking around 15mins to execute.
Can anyone help to fine-tune this??
SELECT c.H_SEC,
c.S_PAID,
c.H_PAID,
table_c.EFF_DATE
FROM MTCH_TBL c
LEFT OUTER JOIN
(SELECT b.SEC_ALIAS,
b.EFF_DATE,
b.INSTANCE
FROM HIST_TBL b
WHERE b.EFF_DATE =
(SELECT MAX (b2.EFF_DATE)
FROM HIST_TBL b2
WHERE b.SEC_ALIAS = b2.SEC_ALIAS
AND b.INSTANCE =
b2.INSTANCE
AND b2.EFF_DATE >= '01-Jan-2007')
OR b.EFF_DATE IS NULL) table_c
ON table_c.SEC_ALIAS=c.H_SEC
AND table_c.INSTANCE = 100;To start with, I would avoid scanning HIST_TBL twice.
Try this
select c.h_sec
, c.s_paid
, c.h_paid
, table_c.eff_date
from mtch_tbl c
left
join (
select sec_alias
, eff_date
, instance
from (
select sec_alias
, eff_date
, instance
, max(eff_date) over(partition by sec_alias, instance) max_eff_date
from hist_tbl b
where eff_date >= to_date('01-jan-2007', 'dd-mon-yyyy')
or eff_date is null
where eff_date = max_eff_date
or eff_date is null
) table_c
on table_c.sec_alias = c.h_sec
and table_c.instance = 100; -
Please can someone help me to build a query
Please can someone help me to build a query for getting the following results. I work with Oracle 9.
My data is about this:
Projectid / Activitycode / Act.DS / Earlystart / ActualStart
{color:#ff0000}P001 / 110M / blabla / 1-1-08 / 1-1-08{color}
{color:#3366ff}P001 / 230M / fdsfds / 31-1-09 / null{color}
P001 / 450M / fsfsd / 1-4-09 / null
P002 / null / null / 1-12-08 / 1-12-08
{color:#3366ff}P002 / 110M / nhggh / 5-2-09 / null{color}
P002 / 750M / wdwdwd / 5-2-09 / null
P002 / 210M / plplplp / 31-12-08 / 31-12-08
{color:#ff0000}P002 / 550M / ewdwd / 5-1-09 / null{color}
I'd like to get one row for each Projectid with the {color:#3366ff}first next Early- or Actualstart{color} {color:#3366ff}after today{color} and one row with the {color:#ff0000}latest early-/actualstart before today{color}. When there are two or more rows with the same date then I want the first (minimum) Activitycode. This last condition makes it insoluble for me!
I've tryed SQL with nested Select-statements in the Where-clause. But I've got still 2 rows per projectid because I select the min(nvl(Earlystart ,ActualStart ) I've tryed SQL with an Select in the FROM-claus with Partion BY, but I can't get it work right.
Can someone show me the right way to solve my problem?How's this?
with my_tab as (select 'P001' projectid,
'110M' activitycode,
'blabla' act_ds,
to_date('01/01/2008', 'dd/mm/yyyy') earlystart,
to_date('01/01/2008', 'dd/mm/yyyy') actualstart
from dual
union all
select 'P001' projectid,
'230M' activitycode,
'fdsfds' act_ds,
to_date('31/01/2009', 'dd/mm/yyyy') earlystart,
null actualstart
from dual
union all
select 'P001' projectid,
'450M' activitycode,
'fsfsd' act_ds,
to_date('01/04/2009', 'dd/mm/yyyy') earlystart,
null actualstart
from dual
union all
select 'P002' projectid,
null activitycode,
null act_ds,
to_date('01/12/2008', 'dd/mm/yyyy') earlystart,
to_date('01/12/2008', 'dd/mm/yyyy') actualstart
from dual
union all
select 'P002' projectid,
'110M' activitycode,
'nhggh' act_ds,
to_date('05/02/2009', 'dd/mm/yyyy') earlystart,
null actualstart
from dual
union all
select 'P002' projectid,
'750M' activitycode,
'wdwdwd' act_ds,
to_date('05/02/2009', 'dd/mm/yyyy') earlystart,
null actualstart
from dual
union all
select 'P002' projectid,
'210M' activitycode,
'plplplp' act_ds,
to_date('31/12/2008', 'dd/mm/yyyy') earlystart,
to_date('31/12/2008', 'dd/mm/yyyy') actualstart
from dual
union all
select 'P002' projectid,
'550M' activitycode,
'ewdwd' act_ds,
to_date('05/01/2009', 'dd/mm/yyyy') earlystart,
null actualstart
from dual)
-- above mimics your table; main query is below:
select mt2.projectid,
mt2.activitycode,
mt2.act_ds,
mt2.earlystart,
mt2.actualstart
from (select mt.projectid,
mt.activitycode,
mt.act_ds,
mt.earlystart,
mt.actualstart,
mt.date_col,
mt.before_after_today,
row_number() over (partition by mt.projectid, mt.before_after_today
order by mt.date_col asc) rn_after,
row_number() over (partition by mt.projectid, mt.before_after_today
order by mt.date_col desc) rn_before
from (select projectid,
activitycode,
act_ds,
earlystart,
actualstart,
coalesce(actualstart, earlystart, to_date('01/01/4000', 'dd/mm/yyyy')) date_col,
case when coalesce(actualstart,
earlystart,
to_date('01/01/4000', 'dd/mm/yyyy')) <= trunc(sysdate) then 1
else 2
end before_after_today
from my_tab) mt) mt2,
(select 1 id, 1 col_id from dual union all
select 1 id, 2 col_id from dual) dummy
where dummy.id = case when mt2.before_after_today = 1 then rn_before
else rn_after
end
and mt2.before_after_today = dummy.col_id
PROJECTID ACTIVITYCODE ACT_DS EARLYSTART ACTUALSTART
P001 110M blabla 01/01/2008 01/01/2008
P001 230M fdsfds 31/01/2009
P002 550M ewdwd 05/01/2009
P002 110M nhggh 05/02/2009 -
I need to fetch records from a table. Please help me to create a query
The Tablename is Employee. It has the following records
Department Empname Gender
Finance Tom Male
Finance Rick Male
Finance Stacy Female
Corporate Tom Male
Corporate Rob Male
I want to select the value of the Gender field from the Employee table corresponding to a Department
If all the values in the Gender field are 'MALE' corresponding to 'finance' in the Department field, the value should be 'MALE'
If there is a value 'FEMALE', the gender corresponding to the Empname 'TOM' should be considered as the genderTables have rows - not records.
Your question is a basic SQL language question - which means you do not know the SQL language. This forum is not a classroom for teaching you the SQL language.
Use the following as the basic outline of how your SQL language statement need to look like for selecting the required from the table:
SELECT
<<sql projection goes here>>
FROM <<table name goes here>>
WHERE <<filter conditions go here>>
{code}
The SQL projection specifies the list of columns the SQL need to return to the caller.
The filter condition is basic predicates and AND and OR can be used for multiple predicates.
Go to http://tahiti.oracle.com and look for the +SQL Reference Guide+ for the Oracle version you are using. The +SELECT+ statement syntax is covered in detail and sample statements are provided.
And please do not expect this forum to be used as a classroom, or expect this forum to do your homework for a class. -
Help needed to tune the Query:Statistics added
Can someone DBA please help me to tune this query:
SELECT DISTINCT K.ATTRIBUTE_VALUE AGENCY_ID,B.PROFILE_NM ,NVL(G.OFFICE_DESC,'--') OFFICE_DESC,f.OFFICE_ID,B.PROFILE_ID,'%' ROLE,'%' LAYOUT,
CASE
WHEN 'flagB' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING')
WHEN 'flagO' = '%' THEN
NVL(J.ISS_GRP_DESC,'ORDERING')
WHEN 'flag' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
ELSE
NVL(J.ISS_GRP_DESC,' ')
END ISS_GRP_DESC,
DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME || '( ' || H.USERID || ' )</a>' ) USER_NAME
FROM
PROFILE_PORTAL B ,
TBL_BDA_AGENCY_RESP_REP C ,
TBL_BDA_AGENCY_OFFICE F,
TBL_BDA_OFFICE G,
USERS_PORTAL H,
TBL_BDA_USR_ISS_GRP I ,
TBL_BDA_ISS_GROUP J,
ATTRIBUTE_VALUES_PORTAL K,
PROFILE_TYPE_PORTAL L
WHERE
B.PROFILE_ID = F.AGENCY_ID (+)
AND B.PROFILE_ID = C.AGENCY_ID (+)
AND G.OFFICE_ID (+)= F.OFFICE_ID
AND H.USERID (+)= C.RESP_USR_ID
AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
AND K.ATTRIBUTE_VALUE IS NOT NULL
AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
AND L.APPLICATION_CD='BDA'
AND NOT EXISTS (SELECT agency_id
FROM TBL_BDA_AGENCY_RESP_REP t
WHERE t.ISS_GRP_ID IN ('%')
AND t.AGENCY_ID = C.AGENCY_ID)
AND K.ATTRIBUTE_VALUE LIKE '%'
AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
AND (to_char(NVL(B.PROFILE_ID,0)) LIKE '%' OR NVL(B.PROFILE_ID,0) IN ('a'))
AND NVL(G.OFFICE_ID,0) IN ('%')
AND (to_char(NVL(C.RESP_USR_ID,'0')) LIKE '%' OR NVL(C.RESP_USR_ID,'0') IN ('k'))
ORDER BY PROFILE_NM
The number of rows in these tables are as follows:
PROFILE_PORTAL -- 2392
TBL_BDA_AGENCY_RESP_REP 3508
TBL_BDA_AGENCY_OFFICE 2151
TBL_BDA_OFFICE 3
USERS_PORTAL 270500
TBL_BDA_USR_ISS_GRP 234
TBL_BDA_ISS_GROUP 2
ATTRIBUTE_VALUES_PORTAL 2790
PROFILE_TYPE_PORTAL 3
The Explain pal nhas given this o/p to me:
SQL> select * from table(dbms_xplan.display) dual;
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
| 0 | SELECT STATEMENT | | 807 | 102K| | 2533 |
| 1 | SORT UNIQUE | | 807 | 102K| 232K| 82 |
|* 2 | FILTER | | | | | |
|* 3 | HASH JOIN OUTER | | 807 | 102K| | 52 |
|* 4 | HASH JOIN OUTER | | 807 | 95226 | | 40 |
|* 5 | TABLE ACCESS BY INDEX ROWID | ATTRIBUTE_VALUES | 1 | 23 | | 2 |
| 6 | NESTED LOOPS | | 7 | 805 | | 37 |
| 7 | NESTED LOOPS OUTER | | 6 | 552 | | 25 |
|* 8 | FILTER | | | | | |
| 9 | NESTED LOOPS OUTER | | | | | |
|* 10 | FILTER | | | | | |
| 11 | NESTED LOOPS OUTER | | | | | |
| 12 | NESTED LOOPS OUTER | | 3 | 141 | | 10 |
|* 13 | HASH JOIN | | 3 | 120 | | 7 |
|* 14 | TABLE ACCESS FULL | PROFILE | 6 | 198 | | 4 |
|* 15 | TABLE ACCESS FULL | PROFILE_TYPE | 1 | 7 | | 2 |
|* 16 | INDEX RANGE SCAN | SYS_C0019777 | 1 | 7 | | 1 |
| 17 | TABLE ACCESS BY INDEX ROWID| TBL_BDA_OFFICE | 1 | 10 | | 1 |
|* 18 | INDEX UNIQUE SCAN | SYS_C0019800 | 1 | | | |
| 19 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 2 | 26 | | 2 |
|* 20 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
| 21 | TABLE ACCESS BY INDEX ROWID | USER_ | 1 | 22 | | 1 |
|* 22 | INDEX UNIQUE SCAN | USER_PK | 1 | | | |
|* 23 | INDEX RANGE SCAN | IDX_ATTVAL_ENTATTID | 1 | | | 1 |
| 24 | TABLE ACCESS FULL | TBL_BDA_USR_ISS_GRP | 234 | 702 | | 2 |
| 25 | TABLE ACCESS FULL | TBL_BDA_ISS_GROUP | 2 | 24 | | 2 |
|* 26 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 1 | 7 | | 3 |
|* 27 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
Predicate Information (identified by operation id):
2 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TBL_BDA_AGENCY_RESP_REP" "T" WHERE "T"."AGENCY_ID"=:B1
AND "T"."ISS_GRP_ID"=TO_NUMBER('%')))
3 - access("I"."ISS_GRP_ID"="J"."ISS_GRP_ID"(+))
4 - access("SYS_ALIAS_1"."ISS_GRP_ID"="I"."ISS_GRP_ID"(+))
5 - filter("K"."ATTRIBUTE_VALUE" IS NOT NULL AND "K"."ATTRIBUTE_VALUE" LIKE '%')
8 - filter(NVL("SYS_ALIAS_1"."RESP_USR_ID",'0') LIKE '%' OR NVL("SYS_ALIAS_1"."RESP_USR_ID",'0')='k')
10 - filter(NVL("G"."OFFICE_ID",0)=TO_NUMBER('%'))
13 - access("L"."PROFILE_TYPE_ID"="B"."PROFILE_TYPE_ID")
14 - filter(UPPER("B"."PROFILE_NM") LIKE '%' AND (TO_CHAR(NVL("B"."PROFILE_ID",0)) LIKE '%' OR
NVL("B"."PROFILE_ID",0)=TO_NUMBER('a')))
15 - filter("L"."APPLICATION_CD"='BDA')
16 - access("B"."PROFILE_ID"="F"."AGENCY_ID"(+))
18 - access("G"."OFFICE_ID"(+)="F"."OFFICE_ID")
20 - access("B"."PROFILE_ID"="SYS_ALIAS_1"."AGENCY_ID"(+))
22 - access("H"."USERID"(+)="SYS_ALIAS_1"."RESP_USR_ID")
23 - access("K"."ENTITY_ID"='PROFILE.'||TO_CHAR("B"."PROFILE_ID"))
26 - filter("T"."ISS_GRP_ID"=TO_NUMBER('%'))
27 - access("T"."AGENCY_ID"=:B1)
Note: cpu costing is off
57 rows selected.
Elapsed: 00:00:01.08
Please help me.
Aashish S.Hello Eric,
Here is the code:
SELECT DISTINCT
K.ATTRIBUTE_VALUE AGENCY_ID,
B.PROFILE_NM ,
NVL(G.OFFICE_DESC,'--') OFFICE_DESC,
f.OFFICE_ID,
B.PROFILE_ID,
'%' ROLE,
'%' LAYOUT,
case
WHEN 'flagB' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING')
WHEN 'flagO' = '%' THEN
NVL(J.ISS_GRP_DESC,'ORDERING')
WHEN 'flag' = '%' THEN
NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
else
NVL(J.ISS_GRP_DESC,' ')
END ISS_GRP_DESC,
DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME ||
'( ' || H.USERID || ' )</a>' ) USER_NAME
from
PROFILE_PORTAL B ,
TBL_BDA_AGENCY_RESP_REP C ,
TBL_BDA_AGENCY_OFFICE F,
TBL_BDA_OFFICE G,
USERS_PORTAL H,
TBL_BDA_USR_ISS_GRP I ,
TBL_BDA_ISS_GROUP J,
ATTRIBUTE_VALUES_PORTAL K,
PROFILE_TYPE_PORTAL L
WHERE
B.PROFILE_ID = F.AGENCY_ID (+)
AND B.PROFILE_ID = C.AGENCY_ID (+)
AND G.OFFICE_ID (+)= F.OFFICE_ID
AND H.USERID (+)= C.RESP_USR_ID
AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
AND K.ATTRIBUTE_VALUE IS NOT NULL
AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
AND L.APPLICATION_CD='BDA'
AND NOT EXISTS
(SELECT agency_id
FROM TBL_BDA_AGENCY_RESP_REP t
WHERE t.ISS_GRP_ID IN (1)
AND t.AGENCY_ID = C.AGENCY_ID)
AND K.ATTRIBUTE_VALUE LIKE '%'
AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
AND (to_char(NVL(B.PROFILE_ID,0))
LIKE '%'
OR NVL(B.PROFILE_ID,0) IN (1))
AND NVL(G.OFFICE_ID,0) IN (1)
AND (to_char(NVL(C.RESP_USR_ID,'0'))
LIKE '%'
OR NVL(C.RESP_USR_ID,'0') IN ('%'))
ORDER BY PROFILE_NM
This is the Query and the query takes some mins. to run in prod environment.
From the Query plan ,I am not able to get any idea for optimization.
Now,Can you tell me which steps I need to follow to run it faster and which all modifications should be made?
Thanks.
Aashish S. -
Help needed in writing a query
Hi all,
Following is the structure of my table.
Data
Key Number
Id Number
Value varchar2(100)
activity_name varchar2(100)
Creation_Date Date
Eval_Point varchar2(100)
In the above table Id is the primary key.
The column eval_point holds only two types of entries 'activation' or 'completion'
The activity_name column holds the name of the activity.
The sample entries in the table are as follows
Key Value activity_name Creation_Date Id Eval_Point
260002 XXX assign_1 2007-09-21 16:58:41.920000 951 activation
260002 XXX assign_1 2007-09-21 16:58:43.392000 953 completion
260002 XXX assign_2 2007-09-21 16:59:03.732000 956 activation
260002 XXX assign_2 2007-09-21 16:59:04.112000 954 completion
260002 XXX assign_3 2007-09-21 16:59:24.331000 958 activation
260002 XXX assign_3 2007-09-21 16:59:24.421000 957 completion
i need to write a query which gives me data in the following format
value id start_date end_date
XXX YYY 2007-09-21 16:58:41.920000 2007-09-21 16:58:43.392000
where start_date is the creation date of the 'activation' and end_date is the creation_date of 'completion'.
Can somebody help?
-thanks
lavanyahello all,
I would like to re frame my question.
this is the output of the base query
select id,instance_key,sensor_target,activity_sensor,creation_date,eval_point from bpel_variable_sensor_values where instance_key=260002;
953 260002 Assign_1 952 2007-09-21 16:58:43.392000 completion
951 260002 Assign_1 952 2007-09-21 16:58:41.920000 activation
956 260002 Assign_2 955 2007-09-21 16:59:03.732000 activation
954 260002 Assign_2 955 2007-09-21 16:59:04.112000 completion
958 260002 Assign_3 959 2007-09-21 16:59:24.331000 activation
957 260002 Assign_3 959 2007-09-21 16:59:24.421000 completion
962 260002 Assign_4 960 2007-09-21 16:59:44.741000 completion
961 260002 Assign_4 960 2007-09-21 16:59:44.640000 activation
964 260002 Assign_5 965 2007-09-21 17:00:05.290000 completion
963 260002 Assign_5 965 2007-09-21 17:00:04.950000 activation
I am trying out this query
select a.instance_key,a.creation_date,b.creation_date,a.id
from bpel_variable_sensor_values a, bpel_variable_sensor_values b
where a.instance_key=b.instance_key
and a.instance_key=260002
and a.eval_point='activation'
and b.eval_point='completion'
and i am getting 25 entries i.e a cartesian product of a.creation_date
260002 2007-09-21 16:58:41.920000 2007-09-21 16:58:43.392000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 16:59:04.112000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 16:59:24.421000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 16:59:44.741000 951
260002 2007-09-21 16:58:41.920000 2007-09-21 17:00:05.290000 951
260002 2007-09-21 16:59:03.732000 2007-09-21 16:58:43.392000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 16:59:04.112000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 16:59:24.421000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 16:59:44.741000 956
260002 2007-09-21 16:59:03.732000 2007-09-21 17:00:05.290000 956
260002 2007-09-21 16:59:24.331000 2007-09-21 16:58:43.392000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 16:59:04.112000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 16:59:24.421000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 16:59:44.741000 958
260002 2007-09-21 16:59:24.331000 2007-09-21 17:00:05.290000 958
260002 2007-09-21 16:59:44.640000 2007-09-21 16:58:43.392000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 16:59:04.112000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 16:59:24.421000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 16:59:44.741000 961
260002 2007-09-21 16:59:44.640000 2007-09-21 17:00:05.290000 961
260002 2007-09-21 17:00:04.950000 2007-09-21 16:58:43.392000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 16:59:04.112000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 16:59:24.421000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 16:59:44.741000 963
260002 2007-09-21 17:00:04.950000 2007-09-21 17:00:05.290000 963
can soembody help me to reduce these to 5 rows. -
Help needed in framing SQL query.
Hi,
I have table having following schema:
PRODUCT_ID INT
DATE DATETIME
ITEMS_SOLD INT
This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
Any help to get the SQL query will be appreciated.
Thanks,
Akshay.PRODUCT_ID DATE ITEMS_SOLD
1 10/10/2011 3
1 11/10/2011 3
1 12/10/2011 3
1 13/10/2011 3
1 16/10/2011 5
2 10/10/2011 4
2 11/10/2011 4
2 12/10/2011 4
2 13/10/2011 4
2 14/10/2011 4
2 15/10/2011 4
2 16/10/2011 4
Output:
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
2 4 7
Explanation of results:
The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
2 4 7
Other case where same PRODUCT_ID have different units sold on each day should be ignored.
I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
-Akshay. -
Help needed to build delete statement
i need to keep last 10 days data+ last day of everymonth data in my table.
this table will grow on daily basis.
ex:
data_date no.of records
2006/02/28 10000
2006/03/31 11000
2006/04/30 12000
2006/05/31 13000
2006/06/09 13100
2006/06/10 13200
2006/06/11 13300
2006/06/12 13400
2006/06/13 13500
2006/06/14 13600
2006/06/15 13700
2006/06/16 13800
2006/06/17 13900
2006/06/18 14000
means last 10 days + last day of evermonth data need to store and remaining all
records i need to delete from this table.
could you help me to build this delete statement in single statement.select * from mytbl;
DD NR
28-02-2006 12000
31-03-2006 10000
30-04-2006 12050
31-05-2006 9500
06-06-2006 13100
07-06-2006 13200
08-06-2006 13300
09-06-2006 13400
10-06-2006 13500
11-06-2006 13600
12-06-2006 13700
13-06-2006 13800
14-06-2006 13900
15-06-2006 14000
16-06-2006 14100
17-06-2006 14200
18-06-2006 14300
17 rows selected.
delete from mytbl
where not
( dd = last_day( dd ) -- Keep last days of months
or dd >= trunc(sysdate) - 10 -- Keep last 10 days
3 rows deleted.
select * from mytbl;
DD NR
28-02-2006 12000
31-03-2006 10000
30-04-2006 12050
31-05-2006 9500
09-06-2006 13400
10-06-2006 13500
11-06-2006 13600
12-06-2006 13700
13-06-2006 13800
14-06-2006 13900
15-06-2006 14000
16-06-2006 14100
17-06-2006 14200
18-06-2006 14300To me...it looks like it does work! -
Urgent help needed....Query..
Hello Experts
Can someone help with writing a particular query. This is the test scenario
CREATE TABLE TEST (MONTH DATE,
AMOUNT NUMBER(17));
INSERT INTO TEST VALUES('01-FEB-06',100);
INSERT INTO TEST VALUES('01-MAR-06',100);
INSERT INTO TEST VALUES('01-APR-06',100);
INSERT INTO TEST VALUES('01-JUN-06',100);
INSERT INTO TEST VALUES('01-JUL-06',100);
INSERT INTO TEST VALUES('01-AUG-06',100);
INSERT INTO TEST VALUES('01-SEP-06',100);
INSERT INTO TEST VALUES('01-OCT-06',100);
INSERT INTO TEST VALUES('01-NOV-06',100);
INSERT INTO TEST VALUES('01-DEC-06',100);
INSERT INTO TEST VALUES('01-JAN-07',100);
INSERT INTO TEST VALUES('01-FEB-07',100);
INSERT INTO TEST VALUES('01-MAR-07',100);
INSERT INTO TEST VALUES('01-APR-07',100);
INSERT INTO TEST VALUES('01-MAY-07',100);
INSERT INTO TEST VALUES('01-JUN-07',100);
INSERT INTO TEST VALUES('01-JUL-07',100);
INSERT INTO TEST VALUES('01-AUG-07',100);
INSERT INTO TEST VALUES('01-SEP-07',100);
INSERT INTO TEST VALUES('01-OCT-07',100);
INSERT INTO TEST VALUES('01-NOV-07',100);
INSERT INTO TEST VALUES('01-DEC-07',100);
INSERT INTO TEST VALUES('01-JAN-08',100);
INSERT INTO TEST VALUES('01-FEB-08',100);
INSERT INTO TEST VALUES('01-MAR-08',100);
INSERT INTO TEST VALUES('01-APR-08',100);
INSERT INTO TEST VALUES('01-MAY-08',100);
INSERT INTO TEST VALUES('01-JUN-08',100);
Ok so thats my test table, I want a query which will give me the sum of the field Amount grouping by Year but it should give me the sum of the month from July 06 till July 07. For Example if i put the Date Range from 2003 to 2006 then it should give me out put by group the year from july till next year jun.
It should look something like this
Year Amount
07-2005/06-2006 5000
07-2006/06-2007 2000
07-2007/06-2008 1200
Can i get a query which will group in the above manner???
Thanks & Regards
vihangSQL> select '07'||extract(year from add_months(month,-7))||
2 '-07'||extract(year from add_months(month,5)) yr,
3 sum(amount) amt
4 from test
5 group by '07'||extract(year from add_months(month,-7))||
6 '-07'||extract(year from add_months(month,5));
YR AMT
072007-072008 1100
072006-072007 1200
072005-072006 500.
Message was edited by:
jeneesh -
Help needed to build simple BRF
Hi,
I am new to BRF and wanted some help from you building a simple BRF, say a look up from the database table.Hi,
I guess you are trying to use BRF function from custom application and not talking about Process-Controlled Workflow.
Yes. You can use BRF from custom application. BRF is just one of functions delivered in NetWeaver level.
http://help.sap.com/saphelp_scm70/helpdata/EN/9a/6b67ce7c26446483af079719edf679/frameset.htm
http://help.sap.com/saphelp_scm70/helpdata/EN/d6/38bb4006d9cc38e10000000a155106/frameset.htm
Regards,
Masa -
Help needed in building a sql query
Hello,
I am using Oracle 10g db.
I have 3 tables table1 and table2 and table3
I am writing one sql query which is like
select table1.a a1,(select distinct b from table2,table3 where table2.id=table3.id and table1.id=table2.id) b1
from table1
Now the b1 value may give more then 1 values so when i am trying to execute the query its giving me error.
What i would like to have is if it gives returns more then 1 value then add that value as a new column means if b1 gives like abc and def as values.
Then i want the sql to return like
acolvalue abc def as a single row.
Is this possible to do?
ThanksHello,
The approach which i took is i wrote a function which gives me the b values , sseparated.
Then i am building a outer query considering the max of b so i just found there are max 10 values which one row is showing.
select b11,b12,b13,,,b10
from (
select table1.a a1,func(select distinct b from table2,table3 where table2.id=table3.id and table1.id=table2.id) b1
from table1)
but now i am facing problem like the value of b1 is a,b,c
i want to use the substr and instr function to get
a as b11
b as b12
c as b13
can anyone pls help me out to write a query? i am getting b11 but other values are somehow not coming.
for b11
i used
substr(b1,1,instr(b1,',',1,1)-1)
Thanks -
Help need to build a report query
Hi all
I am using reports 6i and 10 g db.
I am asked to generate letter format report. The content of letter format will be from employee_deschange_details.edcd_desc field .
The parameter i have to pass is emp_code and dsm_code. Based on it the content should be displayed.
In employee_deschange_detail.edcd_desc field has letter content in a particular way as follows
for example
It is my pleasure to inform you that you have been promoted to the position %DESIGNATION effective from %EFFECTIVE_DATE.The %DESIGNATION and %EFFECTIVE_DATE are identifier which should get replaced by actual value.
The identifiers and its actual value is stored in employee_deschange_detail.edcd_title_name and employee_deschange_detail.edcd_param_value respectively.
the value are stored like |%DESIGNATION|%EFFECTIVE_DATE| in edcd_title_name and in
edcd_param_value the data stores like |GM-FIN|21-JUN-2010|
The user can add extra letter content through a form ,so that the content's may get vary.
Thanks,
RincyHi Arif
If have planned to create PLSQL query as follows but it give message in compilation
Error 0 at line,column 0
REP-0737: Should be a function with return type 'ref cursor'
I havent used plSql query yet, not able to proceed. Please go through and please suggest a best way .
function QR_1RefCurDS return cur_ref_type
is
cursor cur_edcd is
select edcd_code,decode(instr(edcd_desc,'%TABLE1'),0,edcd_desc,substr(edcd_desc,1,instr(edcd_desc,'%TABLE1')-1)) part1,
decode (instr(edcd_desc,'%TABLE1'),0,null,substr(edcd_desc,instr(edcd_desc,'%TABLE1')+length('%TABLE1'),length(edcd_desc))) part2,edcd_serial
from employee_deschange_details
where edcd_orgn=:p_orgn
and (edcd_ctry=:p_ctry or :p_ctry is null)
and (edcd_loc=:p_loc or :p_loc ia null)
and (edcd_oru=:p_oru or :p_oru is null)
and (edcd_code=:deschange_code or :deschange_code is null)
and (edcd_emp_code=:employee_code or :employee_code is null)
order by edcd_emp_code,edcd_serial desc;
v_srl number;
v_part1 varchar2(4000);
v_part2 varchar2(4000);
Cursor cur_param_value
is
select
substr(edcd_title_name,
instr (edcd_title_name, '|', 1, level)+1,
instr (edcd_title_name, '|', 1, level+1) - instr (edcd_title_name, '|', 1, level) -1) res,
substr(edcd_param_value,
instr (edcd_param_value, '|', 1, level)+1,
instr (edcd_param_value, '|', 1, level+1) - instr (edcd_param_value, '|', 1, level) -1) result
from (select edcd_title_name,edcd_param_value from employee_deschange_details where edcd_emp_code =:employee_code
and edcd_code=:deschange_code and edcd_serial=v_srl)
connect by level < length(edcd_title_name)-length(replace(edcd_title_name,'|',''))
Order by length(substr(edcd_title_name,
instr (edcd_title_name, '|', 1, level)+1,
instr (edcd_title_name, '|', 1, level+1) - instr (edcd_title_name, '|', 1, level) -1));
TYpe cur_ref_type is ref cursor;
cur_ref cur_ref_type;
begin
open cur_edcd ;
loop
fetch cur_edcd into v_part1,v_part2,v_srl;
if cur_edcd%found then
open cur_param_value;
loop
fetch cur_param_value into v_title,v_title_value;
if cur_param_value%found then
V_part1=replace(v_part1,v_title,v_title_value);
V_part2=replace(v_part2,v_title,v_title_value);
end if;
exit when cur_param_value%notfound;
end loop;
end if;
exit when cur_edcd%notfound;
end loop;
close cur_param_value;
close cur_edcd;
open cur_ref for (select v_part1,v_part2 from dual);
return(cur_ref);
end;Thanks,
Rincy
Edited by: Rincy Binu on Jul 4, 2010 1:00 PM
Edited by: Rincy Binu on Jul 4, 2010 1:01 PM -
Help needed for SCCM SQL query
Hello.
I have the below query to extract the workstations build date as well as the hardware info. This works fine.
Select distinct
v_R_System.Name0,
v_GS_COMPUTER_SYSTEM.Manufacturer0,
v_GS_COMPUTER_SYSTEM.Model0,
v_GS_COMPUTER_SYSTEM_PRODUCT.Version0,
v_GS_OPERATING_SYSTEM.Caption0,
v_GS_OPERATING_SYSTEM.CSDVersion0,
v_GS_OPERATING_SYSTEM.InstallDate0
From v_R_System
LEFT JOIN v_GS_OPERATING_SYSTEM ON v_GS_OPERATING_SYSTEM.ResourceID=v_R_System.ResourceID
LEFT JOIN v_GS_COMPUTER_SYSTEM_PRODUCT ON v_GS_COMPUTER_SYSTEM_PRODUCT.ResourceID=v_R_System.ResourceID
LEFT JOIN v_GS_COMPUTER_SYSTEM ON v_GS_COMPUTER_SYSTEM.ResourceID=v_R_System.ResourceID
LEFT JOIN v_GS_SYSTEM_CONSOLE_USAGE ON v_R_System.ResourceID=v_GS_SYSTEM_CONSOLE_USAGE.ResourceID
Where v_GS_OPERATING_SYSTEM.Caption0 = 'Microsoft Windows 7 Enterprise' and v_R_System.Is_Virtual_Machine0 =0
order by v_GS_OPERATING_SYSTEM.InstallDate0 desc
Now, I want a report of count of machines built based on "v_GS_COMPUTER_SYSTEM_PRODUCT.Version0" against every month and year of "v_GS_OPERATING_SYSTEM.InstallDate0".
For example, I want to know the number of machines under a particular model (which appears under v_GS_COMPUTER_SYSTEM_PRODUCT.Version0) built in June 2014. In this fashion I want a report for every model count for every month and year available under
InstallDate0 column)
Example:
Jan 2013 -> ThinkCentre M92p -> 55
Jan 2013 -> ThinkCentre M93 -> 40
Feb 2013 -> ThinkCentre M92p -> 10
Feb 2013 -> ThinkCentre M93 -> 39
Jan 2014 -> ThinkCentre M92p -> 20
Jan 2014 -> ThinkCentre M93 -> 25
Feb 2014 -> ThinkCentre M92p -> 12
Feb 2014 -> ThinkCentre M93 -> 35
Can anyone help?After scratching my head a bit, I came up with the below. Do you find any flaw in it?
Select
v_GS_COMPUTER_SYSTEM.Manufacturer0 as Manufacturer,
v_GS_COMPUTER_SYSTEM.Model0 as Model,
v_GS_COMPUTER_SYSTEM_PRODUCT.Version0 as "Model Info",
COUNT(*) as "No. of machines built",
CASE WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '1' THEN 'January'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '2' THEN 'February'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '3' THEN 'March'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '4' THEN 'April'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '5' THEN 'May'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '6' THEN 'June'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '7' THEN 'July'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '8' THEN 'August'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '9' THEN 'September'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '10' THEN 'October'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '11' THEN 'November'
WHEN Month(v_GS_OPERATING_SYSTEM.InstallDate0) = '12' THEN 'December'END as "Month",
YEAR(v_GS_OPERATING_SYSTEM.InstallDate0) as "Year"
From v_GS_COMPUTER_SYSTEM
LEFT JOIN v_GS_OPERATING_SYSTEM ON v_GS_OPERATING_SYSTEM.ResourceID=v_GS_COMPUTER_SYSTEM.ResourceID
LEFT JOIN v_GS_COMPUTER_SYSTEM_PRODUCT ON v_GS_COMPUTER_SYSTEM_PRODUCT.ResourceID=v_GS_COMPUTER_SYSTEM.ResourceID
Where v_GS_OPERATING_SYSTEM.Caption0 = 'Microsoft Windows 7 Enterprise' Group By v_GS_COMPUTER_SYSTEM.Manufacturer0,
v_GS_COMPUTER_SYSTEM.Model0,
v_GS_COMPUTER_SYSTEM_PRODUCT.Version0,
Month(v_GS_OPERATING_SYSTEM.InstallDate0),
YEAR(v_GS_OPERATING_SYSTEM.InstallDate0)
Order by v_GS_COMPUTER_SYSTEM_PRODUCT.Version0 desc -
Help needed for building report with execution method Java Concurrent prog
Hi,
I have saw a report like this:
The report has executable "XML Publisher Data Template Executable", short name as "XDODTEXE", application "XML Publisher",execution method "Java Concurrent program". Also the report has a XML publisher Data Template and Data definition and in the data definition a .xml file is attached.
I could not understand what is the data source?
Could anyone help me on how to build or update this type of report?
Is there any link or help docs which has proper step by step procedure to build this type of xml publisher report?
Please help.
Thanks.The xml file which is attached to the data definition is the data source and it has sql queries and structure of xml file.
Check this out for step-by-step guidance.
http://www.oracle.com/technetwork/middleware/bi-publisher/overview/xmlebsrep-132947.pdf
http://apps2fusion.com/at/ps/51-prabhakar/262-xml-publisher-and-data-template-sql-query-to-develop-bi-publisher-reports
For more on data templates refer user guide
http://download.oracle.com/docs/cd/E10415_01/doc/bi.1013/e12187/T421739T434255.htm
Maybe you are looking for
-
IChat Black screen on Windows XP with AIM 5.9
I am trying to chat with a mac to windows xp with AIM 5.9. I have iChat 3.1.9 (v446) on Tiger 10.4.11. I have turned off my firewall on my computer, running DMZ to my NAT IP and have opened all the necessary ports to my windows user in KY. When I ini
-
A good tutorial for Oracle BI Publisher
Hi, I am new to BI Publisher. I'm using JDeveloper 10.1.3.2 and want to build reports in it. I found BI Publisher a good tool for building reports, based on its features on OTN and now I want a good working tutorial for using it. Is there anything? T
-
How to use connection pool with RDBMSRealm
I am having a problem with the RDBMSRealm. The problem is that the connection defined in the .realm_properties file times out after 1 hour. My solution was to use the connection pool defined in the weblogic.properties file, but the realm_proprties ar
-
Save as for Web gives inappropriate file type estimation
When I go to Save As For Web (and devices) I'm brought to the next screen that allows me to do a multitude of things. I can adjust the resolution of my image with many other settings but I can also, more specifically, change the file type and, upong
-
MySQL - can't see database fields
I've set up a really simple database with names and addresses in it. I want to pull out records based on the State. When I set up my recordset, in the "Columns:" field, it says "No columns found." What did I do wrong in setting up my database. When I