Help needed in getting a query
Hi,
I have two tables issues and comments. Issues is parent table and comments is a child table with issue_id as the foreign key. There are two columns in master table Creation_date and closed_date . As the name suggests they refer to issue creation and closing date. I have say 4 statuses in comments table. Say 'open',moreInfo','Closed','Reopen'. There is also update_time column for the comments_table. So whenver the status is updated date and time is captured. Also when a issue is closed the update_time is entered into closing_date of the issues table as well. Also when the issue is reopened that closing date of the issue will be set to null. I wanted a query to calculate the average time required in closing the issue which I got that from the issues table by doing '-' of closingdate and creation_date.
But now I want to calculate the average time spent on the issues without taking the time spent on the status moreinfo into consideration. Also the status can change at any point of time. THere is no sequence in status change.
I want a SQL query for the above scenario.
Thanks
Hi,
868875 wrote:
Hi,
I have two tables issues and comments. Issues is parent table and comments is a child table with issue_id as the foreign key. There are two columns in master tableIs "master table" the same as issues?
Creation_date and closed_date . As the name suggests they refer to issue creation and closing date. I have say 4 statuses in comments table. Say 'open',moreInfo','Closed','Reopen'. There is also update_time column for the comments_table. So whenver the status is updated date and time is captured. Also when a issue is closed the update_time is entered into closing_date of the issues table as well. Also when the issue is reopened that closing date of the issue will be set to null. I wanted a query to calculate the average time required in closing the issue which I got that from the issues table by doing '-' of closingdate and creation_date.
But now I want to calculate the average time spent on the issues without taking the time spent on the status moreinfo into consideration. Also the status can change at any point of time. THere is no sequence in status change.
I want a SQL query for the above scenario.Maybe you just need to add
comments.status != 'moreinfo' to your WHERE clause. Without more specific information about your daya and your requirements, I can't be sure.
As mentioned before, post your query.
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Always say which version of Oracle you're using.
Similar Messages
-
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; -
Help needed in getting the previous Quarter Data
Hello folks,
I have this procedure where i have to modify the current procedure in the following manner:
I need to get rid of the variables p_start and p_end so that i cannot see them in the crystal report and include the Frequency in the procedure to get the Data based on the Dates.
and Main requirement is" If the Frequency is Quarterly " it should get the previous quarter Data, if "Frequency is monthly" it should return the previous month data.Can anyone please let me know where shud i make changes. Am including the procedure for refernce. Any help is appreciated
Thanks a millioin,
CREATE OR REPLACE PROCEDURE hcsc_recovery_report_h(report_record in out cr_return_types.gen_cursor,
p_start string,
p_end string)
IS
v_startdate date;
v_enddate date;
BEGIN
v_startdate := to_date(p_start, 'YYYY/MM');
v_enddate := last_day(to_date(p_end, 'YYYY/MM'));
open report_record for
select --distinct r.recovery_id
r.event_id,
r.event_case_id,
c.client_id,
c.client_code,
c.client_name,
b.branch_group_code,
b.branch_group_description,
g.employer_group_code,
g.employer_group_name,
e.client_policy_identifier,
e.date_of_incident,
e.event_type_code,
sum(nvl(r.amount, 0)) as amt_received,
nvl(sum(case
when r.amount >= 0 then
rd.fees
else
rd.fees * (-1)
end),
0) as fees,
ec.close_date, *001* commented
(case
when ec.close_date <= to_date(to_char(v_enddate, 'MMDDRRRR') || '235959',
'MMDDRRRR HH24MISS') then
ec.close_date
else
null
end) as close_date, --*001* added
get_case_value(ec.event_id, ec.event_case_id, v_enddate) as case_value,
nvl(etl.fee_percent_flag, 'N') workmans_comp,
max(to_char(r.recovery_date, 'FMMonthYYYY')) Year_Month,
max(to_char(r.recovery_date, 'YYYYMM')) Y_M,
max(to_date(to_char(r.recovery_date, 'MMYYYY'), 'MM/YYYY')) date_MY
from recovery r,
recovery_detail rd,
event e,
client c,
branch_group b,
employer_group g,
event_case ec,
event_type_lookup etl
where r.event_id = e.event_id
and r.event_case_id = ec.event_case_id
and ec.event_id = e.event_id
and rd.recovery_id(+) = r.recovery_id
and r.recovery_date between v_startdate and
to_date(to_char(v_enddate, 'MMDDRRRR') || '235959',
'MMDDRRRR HH24MISS')
and e.client_id = c.client_id
and g.client_id = c.client_id
and b.client_id = c.client_id
and g.employer_group_id(+) = e.employer_group_id
and b.branch_group_id(+) = g.branch_group_id
and e.event_type_code = etl.event_type_code -- SST 130852 04/14/09
group by r.event_id,
r.event_case_id,
c.client_id,
c.client_code,
c.client_name,
b.branch_group_code,
b.branch_group_description,
g.employer_group_code,
g.employer_group_name,
e.client_policy_identifier,
e.date_of_incident,
e.event_type_code,
ec.close_date,
get_case_value(ec.event_id, ec.event_case_id, v_enddate),
nvl(etl.fee_percent_flag, 'N')
having sum(nvl(r.amount, 0)) <> 0
order by c.client_code,
b.branch_group_code,
g.employer_group_code,
r.event_case_id;
Edited by: user11961230 on Oct 20, 2009 9:02 AMuser11961230 wrote:
1. I want to get rid of the p_start and p_end. So how do i declare the v_startdate and v_enddate in the following part?
v_startdate := to_date(p_start, 'YYYY/MM');
v_enddate := last_day(to_date(p_end, 'YYYY/MM'));I'm not sure what you mean by "declare".
In PL/SQL, "declare" means state (at the beginning of a block) that there will be a certain variable with a certain name (such as v_startdate) and datatype (such as DATE). You're already declaring the variables v_startdate and v_enddate correctly, right before the BEGIN statement.
Declaring a variable is not the same as initializing it, that is, giving it a value for the first time. Your next question seems to be about initializing..
2. where exactly shud i include the logic that u have mentioned. sorry a dumb questionIn place of the two assignment statments that reference p_start and p_end.
3. This time am gonna use frequency instead of report_type so that i will get rid of the p_start and p_end from the procedure.Do you mean you want to pass an argument (called frequency) that tells if you want a quarterly or a mionthly report, just like the variable report_type in my example?
If so, replace report_type in my example with frequency.
I think you want something like this:
CREATE OR REPLACE PROCEDURE hcsc_recovery_report_h
( report_record in out cr_return_types.gen_cursor
, frequency IN VARCHAR2
IS
-- Declare local variables:
v_startdate date;
v_enddate date;
BEGIN
-- Initialize v_startdate and v_enddate, depending on frequency
IF frequency = 'QUARTERLY'
THEN
v_startdate := TRUNC ( ADD_MONTHS (SYSDATE, -3)
, 'Q'
v_enddate := TRUNC (SYSDATE, 'Q');
ELSIF frequency = 'MONTHLY'
THEN
v_startdate := TRUNC ( ADD_MONTHS (SYSDATE, -1)
, 'MM'
v_enddate := TRUNC (SYSDATE, 'MM');
END IF;
-- Subtract one second from v_enddate
v_enddate := v_enddate - ( 1
/ (24 * 60 * 60)
open report_record for
select --distinct r.recovery_id
r.event_id,
and r.recovery_date BETWEEN v_startdate
AND v_enddate
...When you post formatted text on this site (and code should always be formatted), type these 6 characters:
(small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.
Edited by: Frank Kulash on Oct 20, 2009 2:37 PM
Changed query to use BETWEEN -
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. -
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,
I am getting this message sandbox environment error no test user account, when downloading any application from iTunes, friend told me to sign out and sign in iTunes it might solve the problem , and i triyed it but still I cannot login I to my itune account. Same message keeping. Popping up, this problem started supricly today.Take a look at the instructions here.
http://www.technogal.net/2012/03/this-is-not-test-user-account-please.html -
Help needed in getting file url
Hi,
I work in a project where i need to get the url of the specified file. The code for that is as,
URL fileURL = Thread.currentThread().getContextClassLoader().getResource();
The required resource is available in the concerned path. But the file url returns null
Can you please help in solving the problem.
Thanks and Regards,
MclarenWhere (text area, label, button) do you want it to do it.
What do you want it do (browse within the local text area, open the default browser...)
Text area, use above, JButton (or alike) and open default browser, use ActionListener and JDIC. -
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: How to get this query?
I am working one a query and the analogy is like:
TABLE TEST has two columns: order_ID, amount
I'd like to get a query that will show
Amount range ---# of order ---total amount
$0 - $999
$1000 - $4,999
$5,000 - $9,999
$10,000 - $19,999
$20,000 - $49,999
$1,000,000
Please post your suggestions.
Thank you in advance.
Jimmy
Message was edited by: Jimmy
JimmyHi Jimmy,
Here is an example please change the column names according to your example.
SELECT '$0 - $99' as range
, count(CASE WHEN sal BETWEEN 0 and 1000 THEN sal END) as count
, sum(CASE WHEN sal BETWEEN 0 and 1000 THEN sal END) total_amount
FROM emp
WHERE case when sal between 0 and 1000 then sal end is not null
UNION ALL
SELECT '$100 - $4999' as range
, count(CASE WHEN sal BETWEEN 1000 and 4999 THEN sal END) as count
, sum(CASE WHEN sal BETWEEN 1000 and 4999 THEN sal END) total_amount
FROM emp
WHERE case when sal between 1000 and 4999 then sal end is not null
UNION ALL
SELECT '$5000 - $9999' as range
, count(CASE WHEN sal BETWEEN 5000 and 9999 THEN sal END) as count
, sum(CASE WHEN sal BETWEEN 5000 and 9999 THEN sal END) total_amount
FROM emp
WHERE case when sal between 5000 and 9999 then sal end is not null
UNION ALL
SELECT '$10000 - $19999' as range
, count(CASE WHEN sal BETWEEN 10000 and 19999 THEN sal END) as count
, sum(CASE WHEN sal BETWEEN 10000 and 19999 THEN sal END) total_amount
FROM emp
WHERE case when sal between 10000 and 19999 then sal end is not null
UNION ALL
SELECT '$20000 - $49999' as range
, count(CASE WHEN sal BETWEEN 20000 and 49999 THEN sal END) as count
, sum(CASE WHEN sal BETWEEN 20000 and 49999 THEN sal END) total_amount
FROM emp
WHERE case when sal between 20000 and 49999 then sal end is not null
UNION ALL
SELECT '$50000 - $1000000' as range
, count(CASE WHEN sal BETWEEN 500000 and 1000000 THEN sal END) as count
, sum(CASE WHEN sal BETWEEN 500000 and 1000000 THEN sal END) total_amount
FROM emp
WHERE case when sal between 500000 and 1000000 then sal end is not null;HTH
Ghulam -
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 - Need to Get Max(Date) from An Unrelated Table in PowerPivot
I have two tables in my Power Pivot model:
Table A (a many table)
Asset
SerialNumber
User
CTUT111
YC112233
Bob
CTUT222
ZZ221144
Susy
CTUT222
ZZ221144
Larry
CTUT333
AB332244
Bob
Table B (a many table, a CSV import from another system)
Asset
SerialNumber
CheckIn_Date
CTUT111
YC112233
6/15/2014
CTUT111
YC112233
6/20/2014
CTUT222
ZZ221144
6/18/2014
CTUT333
AB332244
6/20/2014
I know it appears odd that Table B would have two entries for the same Asset (CTUT111), but it does.
I know I could write a SQL query that gave me the MAX(CheckIn_Date), but I’m not staging these datasets in a SQL server first.
I’m pulling directly from CSV tables.
I don’t want to have bridge tables either, if possible.
So, I’m left with a many-to-many situation in Power Pivot.
I want to add a Calculated Column to Table A, called ‘Latest CheckIn Date’ – which I get from Table B, matching on Serial Number.
So, when I’m done, I would expect the value for Asset=CTUT111 to be 6/20/2014 (since it’s the MAX of a value of dates)
I’m trying this pattern from Marco Russo in which you don’t need to relate two tables to exchange information, but it doesn’t appear to be working.
=CALCULATE (
MAX ( VALUES ( TableB[CheckIn_Date] ) ),
FILTER (
TableB,
'TableA'[SerialNumber]
= TableB[SerialNumber]
I’ve also tried to use LOOKUPVALUE, but I can’t seem to figure it out.
Would appreciate the help.
Thanks in advance.
-EricHi Eric,
Please, try this one formula:
=CALCULATE (
MAXX ( VALUES( TableB[CheckIn_Date] ); TableB[CheckIn_Date] );
FILTER (
TableB;
'TableA'[SerialNumber] = TableB[SerialNumber]
P.S. In my locale I use ";". According to your locale you should use ",".
Truly yours,
Paul -
Help need for Outer Join Query Mysterious Query...
I have two table parent tablea and child tableb
Now
tableb has field by name table_id,keyword_name,keyword_value
tablea has field by name
table_id,table_name
I need a query which would retrieve union of this two set...(for table_name)
1)all table_name having keyword_name='abc' and value=12
2)all the table_name that does not have 'abc' as keyword in tableb.....
Please let me know how it can be done....Ok then, try this.
select
a.table_name
from
tablea a, tableb b
where
a.table_id = b.table_id
and b.keyword_name = 'abc'
and b.value = 12
union
select
c.table_name
from
tablea c
where
not exists (select 1 from tableb d
where d.table_id = c.table_id
and d.keyword_name = 'abc'
) ;To get a faster answer and avoid wrong guesses, I always find it helpful to show sample data and sample output when asking a SQL question. For example:
TableA -----------------
table_id table_name
1 AAA
2 BBB
3 CCC
4 DDD
5 EEE
TableB -----------------
table_id keyword_name value
1 abc 12
1 def 23
2 abc 13
4 def 12
5 abc 13
5 def 12
Desired output of query: -----------------
AAA
CCC
DDD -
Help need in getting thread join to actionperformed event.
Hi,
I am trying to building a small application which should give me the following functionality.
My main function should span two windows. One window(1) will be receiving the input from the user and after the user enter a string and press the OK butten, the other window(2) should display this string and first window should set unvisible.
To have this function working my window(2) should wait for the window(1) ActionPerform event complete and receive the message from it.
Can any of you please help me getting some hints or sample codes for this action to be done.
Thanks.Varad,
Not sure what you are suggesting is what I am looking to do. I believe with your example here that I would need to create a new item table in my current DB in order to recall this data. This table would be populated with the items I selected (checkbox) from the original page. This is one solution, but the issue is that this is dynamic and these values would change as a new search is generated or different values are selected.
Is there anyway in which to make (code) in ApEx so as that the values (i.e. P1_items 123 : 234 : 456) (note that these items are defaulted to colon delimitation by ApEx) are properly formatted so as SQL can read them as independent items. Note if I simply rewrite the original SQL script and replace the :P1_item with generic values (123 , 234 , 456) the SQL operates as intended.
Thank you for your support and help,
Randy -
Help needed in tuning this query
This is the SQL i would like to tune for performace...
The table structure is given below.
The table has about 2 million rows.
From the second day onwards only around 10% of records will be between Load_Start_Time and Load_End_Time. Among these around 50% will have THAMES_URN_WITH_ROLE_SUFFIX as 'TP%'. At present there are unique and primary key indexes on THAMES_URN_WITH_ROLE_SUFFIX .
I'm sure that we need a b-tree index on STG_UPDATE_DATE_TIME as it is the column with good selectivity.
I'm primarily concerned about the substr, instr and reverese on THAMES_URN_WITH_ROLE_SUFFIX.
Also pls. let me know if the order of predicates is right.
Thanks in advance.
SELECT TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN, TPD_STG_TL_SF_LEGAL_OWNER.UPDATE_SOURCE, TPD_STG_TL_SF_LEGAL_OWNER.SOURCE_EXTRACT_DATE_TIME, TPD_STG_TL_SF_LEGAL_OWNER.LEGAL_OWNERSHIP_ISSUE_IND, TPD_STG_TL_SF_LEGAL_OWNER.CONTACTABLE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ADMIN_CONTROL_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.BANKRUPTCY_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ASSIGNED_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.IN_TRUST_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.DIVORCE_CASE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.POA_COP_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.CLEANSING_STATUS, TPD_STG_TL_SF_LEGAL_OWNER.CATEGORY
FROM
TPD_STG_TL_SF_LEGAL_OWNER
WHERE
((TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME > '$$Load_Start_Time'
AND
TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME <= '$$Load_End_Time')
OR
(TPD_STG_TL_SF_LEGAL_OWNER.TPDB_PROCESSED_IDENTIFIER != 'Y') )
AND
SUBSTR(TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX,1,2)='TP'
AND
SUBSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),INSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),'-',1)-1,1)!='S'
========================================
CREATE TABLE TPD_STG_TL_SF_LEGAL_OWNER
THAMES_URN VARCHAR2(35 BYTE) NOT NULL,
UPDATE_SOURCE VARCHAR2(3 BYTE),
SOURCE_EXTRACT_DATE_TIME DATE,
LEGAL_OWNERSHIP_ISSUE_IND CHAR(1 BYTE),
CONTACTABLE_INDICATOR CHAR(1 BYTE),
ADMIN_CONTROL_INDICATOR CHAR(1 BYTE),
BANKRUPTCY_INDICATOR CHAR(1 BYTE),
ASSIGNED_INDICATOR CHAR(1 BYTE),
IN_TRUST_INDICATOR CHAR(1 BYTE),
DIVORCE_CASE_INDICATOR CHAR(1 BYTE),
POA_COP_INDICATOR CHAR(1 BYTE),
THAMES_URN_WITH_ROLE_SUFFIX VARCHAR2(39 BYTE),
THAMES_LEGAL_OWNERSHIP_IND CHAR(1 BYTE),
PRODUCT_HOLDING_ROLE_TYPE VARCHAR2(21 BYTE),
OWNERSHIP_SPLIT_PERCENTAGE NUMBER(3),
SOURCE_SYSTEM VARCHAR2(3 BYTE),
TITLE VARCHAR2(50 BYTE),
FIRST_NAME VARCHAR2(50 BYTE),
MIDDLE_INITIAL VARCHAR2(50 BYTE),
SURNAME VARCHAR2(50 BYTE),
GENDER CHAR(1 BYTE),
BIRTH_DATE DATE,
DEATH_INDICATOR CHAR(1 BYTE),
DEATH_RECORD_DATE DATE,
NATIONAL_INSURANCE_NUMBER VARCHAR2(9 BYTE),
GONE_AWAY_INDICATOR CHAR(1 BYTE),
ADDRESS_LINE_1 VARCHAR2(50 BYTE),
ADDRESS_LINE_2 VARCHAR2(50 BYTE),
ADDRESS_LINE_3 VARCHAR2(50 BYTE),
ADDRESS_LINE_4 VARCHAR2(50 BYTE),
ADDRESS_LINE_5 VARCHAR2(50 BYTE),
POST_CODE VARCHAR2(12 BYTE),
COUNTRY VARCHAR2(50 BYTE),
OVERSEAS_ADDRESS_INDICATOR CHAR(1 BYTE),
ORGANISATION_NAME VARCHAR2(50 BYTE),
TPDB_PROCESSED_IDENTIFIER CHAR(2 BYTE),
CLEANSING_STATUS VARCHAR2(30 BYTE),
CATEGORY VARCHAR2(50 BYTE),
SCHEME_NAME VARCHAR2(50 BYTE),
STG_CREATE_DATE_TIME DATE,
STG_UPDATE_DATE_TIME DATE,
LAST_UPDATED_DATE_TIME DATE
TABLESPACE TPDBS01A_DATA
PCTUSED 0
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
CREATE UNIQUE INDEX TPD_STG_TL_SF_LEGAL_OWNER_PK ON TPD_STG_TL_SF_LEGAL_OWNER
(THAMES_URN_WITH_ROLE_SUFFIX)
LOGGING
TABLESPACE TPDBS01A_DATA
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
NOPARALLEL;
ALTER TABLE TPD_STG_TL_SF_LEGAL_OWNER ADD (
CONSTRAINT TPD_STG_TL_SF_LEGAL_OWNER_PK
PRIMARY KEY
(THAMES_URN_WITH_ROLE_SUFFIX)
USING INDEX
TABLESPACE TPDBS01A_DATA
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
));> If indexes don't help, is the only way to gain REAL
performance gain on this type of query is to
partition the table
If a Full Table Scan on a table takes "too long" (and
this is purely subjective - "too long" is different
for every problem) and indexes can't help, and we
need <100% of the rows, and if partitioning will give
us the performance we desire, is it OK do it ? Also
would STG_UPDATE_DATE_TIME be the best column to do a
index partion ?
For this type of query, partitioning on STG_UPDATE_DATE_TIME would be good.
However, partitioning is not done just for one query. It has to fit in your total design. For example, if you are also doing queries with a predicate like <column with a local unique index but not the partition key> = <constant>, it would have to visit all partitions instead of just one, and those queries would take much longer to execute. You can make the index global, but there all kind of maintenance issues with that. In short: be careful about partitioning and think it through first.
> But is it a good option to partition tables with
total no. of rows between 2 million and 5 million ? I
thought partitioning is better done for tables > 20
million.
Please throw some light on that.
Generally, partitioning is done on bigger tables, yes. But it is not about some specific number of rows. You partition a table when all forecasted use of the table is known, so you can make a good judgement which usages will benefit, which ones won't be affected and which ones are likely to suffer. When the benefits outweigh the disadvantages, you partition...
Above I had an example about queries that are going to suffer. Partitioning is beneficial for example when once in some period you'd have to delete A LOT of old rows. Or when you have some data warehousing queries that need like 10% of only the most recent data in a huge table.
The decision is yours.
Regards,
Rob.
Maybe you are looking for
-
Access database vs Tomcat 1.4.2.9
Good afternoon I'm currently at my practical training and i'm trying te access a MS Access database with a Servlet. I've already done that in the past and there weren't any issues, so it should be a piece of cake. Unfortunately, i think there's an is
-
Incorrect processing status in PR
Hi all, We have a situation where the PR is showing the incorrectiong processing status. The user creates a PR from planned order. If the current price is not sure RFQs are sent. After sendign rfq teh PR processing status changes to RFQ. When qu
-
I want to copy filters from one account to another, in particular to the main account.
I have some filters I imported from Eudora to Thunderbird. I want these filters to work on all accounts. I know that I can copy msgFilterRules.dat from one account to another, but there seems to be no entry in my profile folder for one account. It is
-
I recently updated to the new version of MobileMe iCal. Now I cannot sync through a proxy server. If I take my computer off the proxy, iCal syncs fine. When I put it back on, it quits syncing. All my other MobileMe data is syncing fine through the pr
-
I want get Netflix and need home sharing. I found library but no screens for home sharing.