Need help with sql query
Dear all,
I have a sql like query below
SELECT min (G.TRANSACTION_DATE), D.REQUEST_NUMBER
MTL_TXN_REQUEST_HEADERS D,.
MTL_TXN_REQUEST_LINES, E.
MTL_MATERIAL_TRANSACTIONS G,.
Mtl_Transaction_Types I have
WHERE D.HEADER_ID = E.HEADER_ID
AND G.TRANSACTION_TYPE_ID = I.TRANSACTION_TYPE_ID
AND Upper (I.Transaction_Type_Name) = Upper ('TEC outcome')
AND E.LINE_ID = G.MOVE_ORDER_LINE_ID
AND D.MOVE_ORDER_TYPE = 5
TO_DATE (G.TRANSACTION_DATE) BETWEEN TO_DATE('01-JAN-2014') AND TO_DATE('31-DEC-2014')
D.REQUEST_NUMBER GROUP
I need to get the first number of the application and finally ask for number based on the date of the transaction, how can I get the number of name application and based on the date of the transaction for the same query, please help me.
above query is back under results
If the query should return a line with the number of application like 2383 based on minimum transaction date and another column based on the maximum transaction date, please help me.
so in the example above, it must return
FIRST REQUEST NUMBER LAST NUMBER
2383 1886
Thank you
select min(request_number) keep(dense_rank first order by transaction_date asc ) request_number_min , min(request_number) keep(dense_rank first order by transaction_date desc) request_number_max from ( select min(g.transaction_date) transaction_date , d.request_number from mtl_txn_request_headers d , mtl_txn_request_lines e , mtl_material_transactions g , mtl_transaction_types i where d.header_id = e.header_id and g.transaction_type_id = i.transaction_type_id and upper(i.transaction_type_name) = upper('WIP Issue') and e.line_id = g.move_order_line_id and d.move_order_type = 5 and to_date(g.transaction_date) between to_date('01-jan-2014') and to_date('31-dec-2014') group by d.request_number )
Tags: Database
Similar Questions
-
need help with sql query dates
Hello
I have a sql query I need to extract some info between data dates. Where clause in this query is:
WHERE CPD_BUS_UNIT =: ESI_PRM_1
AND CPD_VOUCHER_DATE > =: P_DATE_FROM
AND CPD_VOUCHER_DATE < (: P_DATE_TO + 1).
When I run the query into a toad, I can view the data, but not the execution plan. It gives an error ORA-00932 inconsistent Datatypes.
But when I remove (+ 1): P_DATE_TO, I can c the execution plan and data. The data will be different from the previous.
Please suggest how to rewrite the query.Can you please give it a try?
WHERE CPD_BUS_UNIT=:ESI_PRM_1 AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM) AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1)
Concerning
-
Need help with sql query performance
Dear all,
I have a sql like query below, I need to give the following query please help me identify which statement I should tune to have better performanece.
Select rownum LINE_NUM,
A.LINE_ID,
TO_CHAR (A.INVITMID),
TO_NUMBER (A.PICKQTY),
UNLOADINGPNT NULL,
RRNUM NULL,
WORKORDNUM NULL,
WORKORDDESC NULL,
A.PONUM,
DTR_DUMB NULL,
A.DESCRIPTION,
FROM_SUB NULL,
TO_SUB NULL,
NO SOURCE,
ASSET_NUMBER NULL,
A.RECEIPTNUM,
MOVEORD NULL,
FROM_LOC NULL,
TO_LOC NULL,
MSD_NUM NULL,
CONTAIN_LINE NULL,
A.UOM,
A.PO_RELEASE
de)
Select headerid Po.Po_Header_Id,
rcv1. Po_Line_Id LINE_ID,
rcv1.item_id INVITMID,
(NVL(Rcv1.Transact_Qty,0)-NVL(rcv2.transact_qty,0)) PICKQTY,
Po.Segment1 PONUM,
Rcv1.Receipt_Num RECEIPTNUM,
Rcv1.Item_Desc DESCRIPTION,
Rcv1.Transact_Uom GLU,
Rcv1.Po_release
Po_Headers_All in.,.
(Select rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, SUM (rcv3. Transact_Qty) Transact_Qty, rcv3. PO_RELEASE OF)
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "EXPENSES".
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
UNION ALL
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND B.ITEM_ID IS NULL
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "WORKSHOP".
D.PO_RELEASE_ID AND = A.PO_RELEASE_ID) rcv3
GROUP BY rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, rcv3. Rcv1 PO_RELEASE),
(SELECT A.PO_LINE_ID,
Sum (A.Quantity) transact_qty,
A.PO_HEADER_ID,
C.RECEIPT_NUM
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "RETURN to the RECEPTION"
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
A.PO_LINE_ID, A.PO_HEADER_ID, C.RECEIPT_NUM GROUP) Rcv2
Where Po.Po_Header_Id = Rcv1.Po_Header_Id (+)
And Rcv1.Po_Line_Id = Rcv2.Po_Line_Id (+)
And Rcv1.Receipt_Num = Rcv2.Receipt_Num (+)
And Rcv1.Transact_Qty <>Nvl(Rcv2.Transact_Qty,999999999)
Group of po.po_header_id, rcv1.po_line_id, po.segment1, rcv1.receipt_num, rcv1.item_id, Rcv1.Item_Desc, rcv1. TRANSACT_UOM, rcv1. PO_RELEASE, (NVL(Rcv1.Transact_Qty,0)-NVL(RCV2.transact_qty,0))) has
Is my version of the database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Please find the attached PLAN to EXPLAIN.
Thank you
May be essentially the same join (between a, b, c and d) twice instead of three times
sounds like it could be done with a single join (between a, b, c, and d), but you do not some columns than the columns of rcv1 rcv2
We can work on what we can see only
Select rownum line_num,
rcv1.po_line_id line_id,
TO_CHAR (rcv1.item_id) invitmid,
NVL(rcv1.transact_qty,0) - nvl(rcv2.transact_qty,0) pickqty,
unloadingpnt null,
rrnum null,
workordnum null,
workorddesc null,
Po. Ponum Segment1,
dtr_dumb null,
description of the rcv1.item_desc,
from_sub null,
to_sub null,
No source,
asset_number null,
rcv1.receipt_num receiptnum,
moveord null,
from_loc null,
to_loc null,
msd_num null,
contain_line null,
Glu rcv1.transact_uom,
rcv1.po_release
of po_headers_all in.
left outer join
(select a.po_header_id,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description item_desc,
a.unit_of_measure transact_uom,
Sum (a.Quantity) transact_qty,
d.release_num po_release
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
po_line_id,
destination_type_code,
unit_of_measure,
quantity
of rcv_transactions
where upper (a.transaction_type) = "to DELIVER".
and upper (a.destination_type_code) ('charge', 'WORKSHOP')
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
where upper (a.destination_type_code) = "EXPENSES".
or (upper (a.destination_type_code) = 'WORKSHOP'
and b.item_id is null
)
A.po_header_id group,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description,
a.unit_of_measure,
d.release_num
) rcv1
On po.po_header_id = rcv1.po_header_id
left outer join
(select a.po_line_id,
Sum (a.Quantity) transact_qty,
a.po_header_id,
c.receipt_num
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
quantity
of rcv_transactions
where upper (a.transaction_type) = "RETURN to THE RECIPIENTS.
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
A.po_line_id group,
a.po_header_id,
c.receipt_num
) rcv2
On rcv1.po_line_id = rcv2.po_line_id
and rcv1.receipt_num = rcv2.receipt_num
where rcv1.transact_qty! = nvl(rcv2.transact_qty,999999999)
Concerning
Etbin
-
Need help with SQL Query - change of name history of audit table.
I need your help to find the result in the following way...
Emp No New_name Old_Name ----------------------------------------------- 1 Name3 Name2 1 Name2 Name1
Thank you...create table emp(emp_id number(10), emp_name varchar(50), constraints emp_pk primary key(emp_id) ); create table emp_audit( audit_id number(10), emp_id number(10), emp_name varchar(50), audit_date date, constraints emp_audit_pk primary key (audit_id), constraints emp_audit_emp_fk foreign key(emp_id) references emp(emp_id)); insert into emp values(1,'Name3'); insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date) values (1, 1, 'Name1', to_date('14-08-2011', 'dd-mm-yyyy')); insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date) values (2, 1, 'Name2', to_date('15-08-2011', 'dd-mm-yyyy')); commit;
Dipabkar Bédard (DB) wrote:
We write is the query without using "partition by" in oracle...?
with t as ( select audit_id, emp_id, emp_name, row_number() over(order by audit_id) rn from emp_audit order by emp_id, audit_id ) select a.audit_id, a.emp_id, a.emp_name old_name, nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name from t a left join t b on ( b.emp_id = a.emp_id and b.rn = a.rn + 1 ) / AUDIT_ID EMP_ID OLD_NAME NEW_NAME ---------- ---------- -------------------------------------------------- ------------ 1 1 Name1 Name2 2 1 Name2 Name3 SQL>
And without analytical functions:
with t1 as ( select audit_id, emp_id, emp_name from emp_audit order by emp_id, audit_id ), t2 as ( select audit_id, emp_id, emp_name, rownum rn from t1 ) select a.audit_id, a.emp_id, a.emp_name old_name, nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name from t2 a left join t2 b on ( b.emp_id = a.emp_id and b.rn = a.rn + 1 ) / AUDIT_ID EMP_ID OLD_NAME NEW_NAME ---------- ---------- -------------------------------------------------- ---------- 1 1 Name1 Name2 2 1 Name2 Name3 SQL>
SY.
-
Need help with sql query involving distinct and County
I have 2 tables and I want to get the number of specific names. Find the details below. It's hard to explain but I will try to provide as much detail as I can.
Table A:
ID of the SR
1001 1
1002 2
2 1003
1004 3
Table B:
Name of the key SrNew
1 David 1001
2 James 1002
3 James 1002
4 James 1003
5 James 1004
6 Mike 1004
Result: I'm looking:
Count names such as if the name appears for the same ID of Table A two times, and then only count 1.
Name of County
David 1
James 2 (1002 and 1003 for the same ID (ID #2) so count as 1 for this and then 1 more for 1004 and ID 3)
1 Mike
I have following question:
SELECT distinct (b.Name), a.ID
FROM TableA, TableB b
Where a.Sr = b.SrNew Group By b.Name, a.ID
and as a result I get:
ID name
David 1
James 2
3 James
3 Mike
Now, I want to just the number of each name with the result, but don't know how I can do this with a sql?
Thanks in advance.Who help me?
SELECT b.Name, count(distinct a.ID) FROM TableA a, TableB b Where a.Sr = b.SrNew Group By b.Name
Nicolas.
-
Need help with SQL query (10 years since I have SQL)
Hi guys,.
I tried to remove some rust SQL. I did not go to SQL within a certain time.
Here are the tables (% = ent $ = varcchar)
-----------------
RESULT
-----------------
% RESULT_ID-$ RC-% YEAR_ID - PERIOD_ID-% CONTRACT_NO-% value %
20841---1439---83---37---010427102---1
20842---1439---83---41---010427102---2
20843---1439---84---37---010427102---3
20844---1439---84---41---010427102---4
20845---1439---83---34---010427102---5
-----------------
YEARS
-----------------
YEAR_ID - YEAR_DESC
83 2010-2011
84 2011-2012
-----------------
PERIOD
-----------------
PERIOD_ID - PERIOD_DESC
34 14
37 02
41 03
What I want is to get the last period of each year in the RESULT table. (I'll work the rest of the WHERE statement myself, because I have omitted some news, or columns for simplicity)
Note that I can't rely on the ID of the period, as the chronological order is not respected.
In the scenario above, I should GET
% RESULT_ID-$ RC - YEAR_ID - PERIOD_ID-% CONTRACT_NO-% % value %
20844---1439---84---41---010427102---4
20845---1439---83---34---010427102---5
I have the following, but it only returns values if the year is the last time!
SELECT DISTINCT RESULTS. RESULT_ID, RESULT. RC, RESULT. PERIOD_ID, RESULT. YEAR_ID, RESULT. CONTRACT_NO, YEARS. YEAR_DESC
RESULT, YEARS
WHERE TO TRAIN. YEAR_ID = YEARS. YEAR_ID AND - it is my problem, I want the last period for each year.
RESULT. PERIOD_ID = (SELECT PERIOD_ID FROM PERIOD WHERE CAST (PERIOD_DESC AS INT) = (Select MAX (CAST (PERIOD_DESC AS INT)) of the period)) - I think it works fine I'm able to get the last period
ORDER BY YEARS. YEAR_DESC;
Published by: 935079 on May 17, 2012 11:32
Add space not formatted tabs
Published by: 935079 on May 17, 2012 11:35Your way to present the data that makes it very tedious to create test data. Next time please simply provide CREATE TABLE and INSERT statements so that we can all share the same test data.
Without test data, I think you want Frank solution with a very minor change: order value instead of id, then the number of line 1 is the highest value.
with GOT_R_NUM as ( SELECT r.* -- or list the columns you want , ROW_NUMBER() over(partition by R.YEAR_ID, R.CONTRACT_NO order by -- P.PERIOD_ID P.PERIOD_VALUE DESC NULLS LAST) AS r_num FROM result r JOIN period p ON r.period_id = p.period_id ) SELECT * -- or list all columns except r_num FROM got_r_num WHERE r_num = 1;
-
Oracle Version: 11.2.0.2.0
I need assistance with the output of the query. Here is the table.
With Tbl_Nm as
(
Select 'ABC1' SYSTEM_ID, REGION 'US', 'CHI' SUB_REGION 4000 BALANCE, to_date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') LAST_UPD_TIME, 'A' FLAG of union double all the
Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual
)
Select * from tbl_nm
I need the output below.
PQR2 UK MC 2600 1 OCTOBER 2012 04:45
ABC1 US NY 3500 October 1, 2012 06:45
LMN3 UK BT 2500 November 1, 2012 07:45
The need the disc according to this system_id flagged as "A". But if the last disc of 'd' then it must show that the amount, but the file should be displayed in 'A '.
I've tried a few and got stuck. Help, please. Not able to get a balance '.
This question is a bit similar to needing help with a query result
With Tbl_Nm as
(
Select 'ABC1' System_Id, region 'US', 'CHI' Sub_Region, 4000 balance, To_Date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') Last_Upd_Time, 'A' flag of double Union All
Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual
)
Select System_Id, region, Sub_Region, Balance, Last_Upd_Time of Tbl_Nm T1
where t1. Last_Upd_Time = (select max (Last_Upd_Time) in the Tbl_Nm T2 where T1.) SYSTEM_ID = T2. SYSTEM_ID)
So maybe you'd then
ORDER BY DECODE(flag,'D',9,1) ASC...
to get the Ds at the end of the list.
or
ORDER BY CASE WHAT flag = has ' (your other filters) AND then 9 or 1 end CSA,...
HTH
-
Need help with SQL/PL/SQL for Dates
Hi Experts - need help with a SQL query.
I need to insert some date fields in a table called CALENDAR_PERIOD.
Current data in CALENDAR_PERIOD table with their data types:
STARTPERIOD (DATE) YEAR (NUMBER) PERIOD_LABEL (Varchar2 255)
02/11/2014 2014 2014/02/11 SUN
03/11/2014 2014 14/03/11 MON
04/11/2014 2014 11/04/14 MAR
I have to increment above values up to the year 2025. I don't know how to write SQL and increment of these values.
Ex: My next value should insert: 05/11/2015 2014 11/05/14 WED like that I need to insert data until 12 31, 2025.
Can you please help me with PL/SQL block?
Really appreciate your help!
DB version:
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE Production 11.2.0.3.0
AMT for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Thank you
SandyHello Sandy,
Maybe something like
INSERT INTO calendar_period (startperiod, year, period_label)
SELECT DATE '' 2014-11-04 + LEVEL
, TO_NUMBER (TO_CHAR (DATE '' 2014-11-04 + LEVEL, "YYYY"))
, TO_CHAR (DATE '' 2014-11-04 + LEVEL, "MM/DD/YY DY")
OF the double
CONNECT BY LEVEL<= date="" '2025-12-314="" -="" date="">=>
;
((mais je ne comprends pas pourquoi nous créons une telle table "année" et "period_label" peuvent être calculé à partir de startperiod))
Best regards
Bruno Vroman.
-
Under Update taking 2 h complete 3000 sets.
UPDATE ARR_TRANSACTIONS ARR
SET = NUMBER99
(SELECT ARR_1.NUMBER99
OF ARR_TRANSACTIONS ARR_1, ARR_HEADER BH
WHERE ARR_1.ARR_ID = BH. ARR_ID
AND BH. FLAG = "Y".
AND ARR_1.LINE_ID = ARR. ORIG_INV_LINE_ID
AND ARR_1.NUMBER9 IS NOT NULL
AND ROWNUM = 1)
WHERE ARR BATCH_ID = 26219
AND ARR. NUMBER99 IS NULL
I added more some condition where to reduce cost and its working fine. But I need to rise more than performance on SQL.
Please help with SQL.
I do not see the number of 3000 lines in the plan - so I guess that the optimizer does not compute with the correct numbers. Could generate the plan with dbms_xplan.display_cursor? This could tell us something about filter predicates and access.
In the given situation, I would check:
- is the access to the index in step 1 (filtered by the relevant conditions: this could be BATCH_ID = 26219) return actually 248 entries (or something similar)?
- Access table in step 2 returning 204 lines (or something similar) after applying the filters given? If the number of lines is much bigger then a Nested Loops is perhaps not a good idea.
To make this much simpler check, you could create a plan with statistics of content (RowSource) given that the plan containing the real and the number of estimated rows.
If the estimated cardinalities are not plausible the next question would be if the statistics are strong and up to date.
-
need help with the query, thx
Hello
I need a little help with the query I have to write;
the table has 4 columns:
what I am asking is the following result: salary according to the latest available yearcol1 col2 col3 col4 emp_name empl_id salary year content of data: col1 col2 col3 col4 smith 12 1200 1999 smith 12 1340 2000 smith 12 1500 2001 jones 13 1550 1999 jones 13 1600 2000 aron 14 1200 2002
i.e.
ID appreciate some guidance on how to achievesmith 12 1500 2001 jones 13 1600 2000 aron 14 1200 2002
Thank you
Rgdsselect *from (select col1, col2,col3, col4,row_number() over(partition by col1 order by col4 desc) rn from
) where rn=1 -
Help with SQL Query (Subselects)
Hello community,
IAM a new Member in this forum. The first excuse my English, my native language is German.
In my workplace, we have a great Orcle Database 11 g with 30 different tables for production control issues.
I try to get a couple of different information from the database, so I started with SQL of the query, but for this problem, I wasn't able to write a query to work.
In this case, I have 2 tables:
Table 1:
ID; ORDER_NR; DESCRIPTION; CREATE_DATE
1; A500236; CLEAN HOUSE; 20/02/2012
2; A623555; REPAIR CAR; 10/01/2012
3; A866944; MAINTAIN EQUIPMENT; 11/02/2012
Table 2:
ID; ORDER_NR; WO_STEP; STEP_DATE; EMPLOYEE
1; A500236; A; 21/02/2012; W0010
2; A500239; F; 21/02/2012; W0010
3; A500239; S; 22/02/2012; W0027
4; A500239; R; 23/02/2012; H0034
5; A500239; U; 25/02/2012; L0099
6; A263555; A; 15/01/2012; G0009
7; A263555; C; 17/01/2012; S0039
5 V A263555; R; 18/01/2012; K0059
9; A263555; U; 19/01/2012; A0048
10; A866944; A; 13/02/2012; H0034
11; A866944; B; 13/02/2012; L0035
12; A866944; G; 17/02/2012; D0084
13; A866944; U; 23/02/2012; S0039
And the result of my query should look like this:
ORDER_NR; DESCRIPTION; CREATE_DATE; A_STAT_AGE; R_STAT_AGE; U_STAT_AGE
A500236; OWN HOME; 20/02/2012; 5; 3; 1
A623555; REPAIR CAR; 01/10/2012; 42; 39; 38
A866944; MAINTAIN EQUIPMENT; 11/02/2012; 15; 4; 3
The age of my query result should be calculated from the date of the creation of the order.
I would like to know 2 things, one is how old was the order when they reached this status, R and U.
The second, that is, how long did you order remaining on A stat, R and U (and if possible all the others too)
It can happen that not every order reaches every State, so he ca go directly from A you in this case I want to display a generic character in this row/column
I hope you all know what I mean and what result to expect.
Thanks for your help.
Reinhard W.Hi, Reinhard,
990524 wrote:
Hi Frank,.I thank you for your professional response and excuse my non-professional way to clarify my question.
I have now already read and understand how to ask good questions, but is there an easy an inexpensive way to run a database on my computer at home?You can download the Oracle database from this site. The Express edition is easier to install. It lacks a few features that the Enterprise edition (for example, partitioning table and safety of level line), but most of the things work in all editions of Oracle.
All editions are free if you do not use them for Production applications. Of course, at this price (or lack thereof), you get Oracle support.I have already noticed that the syntax SQL for Oracle differ from other DBMSS.
Yes and some features are different in different products.
Your query works perfectly, thank you.
Now I want to refine my (your) query, is there a way to display a range of day within 1 day? As 0.5 day to half a day between two State timestamp.
Of course, you can do it. After the exact output desired of the sample data that I posted. If the sample data do not show what you need to do, then after a few different examples of data that makes.
My table contains the Date and time in a row, I forgot to mention that.
After a CREATE TABLE statement. I was guessing a lot of things that may be important. For example, I assumed you were using a DATE for date and time column. So it is only reasonable to do so, but maybe it's not what looks like at your table.
I tried something like this:
SYSDATE - MIN ( CASE WHEN t2.wo_step = 'A' THEN t2.step_date END ) AS Age_A
But it gives me an error of arithmetic overflow and not die difference in the Date and time or days with decimal friction.
There are only about 5.4 million possible days with DATEs of Oracle. Is only 7 digits and Oracle can treat approximately 39 numbers without overflow errors, so I don't see how this can happen if t2.step_date is really a DATE. This is an example of why you need to publish a CREATE TABLE statement.
-
Need help with the query. Help, please
Hey everyone, need your help. Thank you in advance. In my view, there is function Pivot. Just do not know how to use this function. I have the query that works. The result is:
11-111-1111 Vlad 16505 01/04/2013 5 August 13 dental plan pre-tax amount 29,65
11-111-1111 Vlad 16505 01/04/2013 dental pre-tax 5 August 13 Plan level EE + SP
11-111-1111 16505 Vlad 01/04/2013 5 August 13 pre-tax Option TOP dental plan
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax dental care plan pay the value
11-111-1111 16505 Vlad 01/04/2013 dental pre-tax 5 August 13 Plan period Type
11-111-1111 Vlad 16505 01/04/2013 amount pre-tax medical Plan of 5 August 13 149
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Medical Plan level EE + SP
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Plan medical Option MED
11-111-1111 Vlad 16505 01/04/2013 5 August 13 plan pre-tax pay value
11-111-1111 16505 Vlad 01/04/2013 5 August 13 pre-tax Medical Plan period Type
11-111-1111 Vlad 16505 01/04/2013 5 August 13 pre-tax Plan PPO medical Plan
11-111-1111 Vlad 16505 01/04/2013 5 August 13 Vision Plan amount 5.94 pre-tax
But I need the result to be
Amount of SSN ID name item level Option PayValue period Type
11-111-1111 Vlad 16505 01/04/2013 null null high of 5 August 13 pre-tax Dental Plan 29,65 EE + SP
11-111-1111 Vlad 16505 01/04/2013 null null MED 5 August 13 149 medical plan pre-tax EE + SP
11-111-1111 Vlad 16505 01/04/2013 Vision Plan before taxes of 5 August 13
Select distinct
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as EMPLOYEE_FULL_NAME,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as Date_Of_Hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_valueOf
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1'
order of petf.element_name;Change with your query
SELECT * FROM (select distinct)
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as employee_full_name,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as date_of_hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_value
Of
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1')
PIVOT (MAX (screen_entry_value) FOR (name) TO ("Amount" AS 'Amount', 'level' AS 'level', 'Option High' AS 'High Option', 'Pay the value' AS 'Value to pay', 'Period of Type' AS 'Type period'))
order by element_name;
(GOLD)
SELECT ssn,
Employee_number,
employee_full_name,
date_of_hire,
effective_start_date,
element_name,
Max (decode (Name, 'Amount', screen_entry_value)) 'amount. "
Max (decode (Name, 'Level', screen_entry_value)) 'level ',.
MAX (DECODE (name, "High Option", screen_entry_value)) "High Option",
MAX (DECODE (name, 'Value of pay', screen_entry_value)) 'value of pay. "
MAX (DECODE (name, 'Period Type', screen_entry_value)) 'period of Type '.
FROM (select distinct)
' 11-111-1111 "as ssn,
WOMEN'S WEAR. Employee_number,
"Vlad" as employee_full_name,
TO_CHAR (papf.start_date, "MM/DD/YYYY") as date_of_hire
a.effective_start_date,
PETF.element_name,
pivf. Name,
peevf.screen_entry_value
Of
PER_all_PEOPLE_F women's wear
per_assignments_f A
pay_element_types_f petf
pay_element_links_f pelf
PAY_ELEMENT_ENTRIES_F penf
PAY_ELEMENT_ENTRY_VALUES_F peevf
pay_input_values_f pivf
WHERE
PETF.element_name ('Dental Plan before taxes', 'Medical Plan before taxes', "Vision Plan before taxes")
and petf. ELEMENT_TYPE_ID = pelf. ELEMENT_TYPE_ID
and (trunc (sysdate) BETWEEN pelf. EFFECTIVE_START_DATE AND pelf. EFFECTIVE_END_DATE)
and (pelf. ELEMENT_LINK_ID = penf. ELEMENT_LINK_ID and a.assignment_id = penf. ASSIGNMENT_ID)
and (trunc (sysdate) BETWEEN penf. EFFECTIVE_START_DATE AND penf. EFFECTIVE_END_DATE)
and penf. ELEMENT_ENTRY_ID = peevf. ELEMENT_ENTRY_ID
and peevf. INPUT_VALUE_ID = pivf. INPUT_VALUE_ID
AND papf.employee_number IS NOT NULL
AND A.assignment_type = 'E '.
AND A.person_id = papf.person_id
and papf.effective_end_date > sysdate
and a.effective_end_date > sysdate
and (trunc (sysdate) BETWEEN women's wear. EFFECTIVE_START_DATE AND women's wear. EFFECTIVE_END_DATE)
and a.effective_start_date = (select MAX (effective_start_date) from PER_ASSIGNMENTS_f where assignment_id = a.assignment_id)
and a.assignment_id = 42643
and a.assignment_status_type_id = '1')
GROUP BY ssn, employee_number, employee_full_name, date_of_hire, effective_start_date, NOM_ELEMENT
order by element_name;
-
Hello
I have a table named WORK_CODES
There only a single column CODE
The CODE values are
YES
NO.
A
B
C
I get a connection variable: var1
If: var1 is TRUE = > YES, I'll be back
If: var1 is NOT TRUE = > I would alternate record in the WORK_CODES table.
The tricky part is that it must be managed in a SQL query.
Any help on this is appreciated.
Thank you
Pradeep
The first problem I see is that SQL does not support the Boolean data type. Then you must consider changing the data type of your variable binding.Assuming that you change it to integer where 1 = 0 = false and true, you can do
I guess I misunderstood. You can do it simply.
select * from
where (:var = 'TRUE' and code = 'YES') or (:var = 'NOT TRUE' and code != 'YES') Published by: Karthick_Arp on January 14, 2010 23:30
-
Need help with a query of type "connect by level.
Hello, I recently met 'connect by level' and I think he can solve my problem, but maybe not. I would like to create rows of data where the number of rows created varies according to the data from the original table.
It works:
with times like
(select to_date (' 26/01/2014 01:00 ',' dd/mm/yyyy hh24:mi:ss') starttime,)
TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime
the double)
Select starttime, stoptime, starttime + rownum / 24
of the time
connect by level < =.
(Select trunc ((stoptime-starttime) * 24: 2) at the time)
I would like to do something similar for several lines (following does not work)
with times like
(select to_date (' 26/01/2014 01:00 ',' dd/mm/yyyy hh24:mi:ss') starttime,)
TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime
of the double
Union
Select to_date (' 25/01/2014 18:00 ',' dd/mm/yyyy hh24:mi:ss') starttime.
TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime
the double)
Select starttime, stoptime, starttime + rownum / 24
of the time
connect by level < =.
(Select trunc ((stoptime-starttime) * 24: 2) at the time)
I need to stay away from solutions of PL/SQL, this query will be wrapped in an application that can not handle the PL/SQL, going and coming from the database (I also suck in PL/SQL).
Any help would be greatly appreciated, I have no knowledge here, I tried to read some of the documentation on hierarchical queries, but it is not yet clicking.
Thank you!
Or also:
SQL > WITH times
2 ALSO (SELECT TO_DATE (' 01:00 26/01/2014 ', "hh24:mi:ss dd/mm/yyyy") Starttime)
3, TO_DATE (' 01/26/2014 03:00 ', 'hh24:mi:ss dd/mm/yyyy') Stoptime
4 FROM TWO
5 UNION
6 SELECT TO_DATE (' 25/01/2014 18:00 ', "hh24:mi:ss mm/dd/yyyy") Starttime
7, TO_DATE (' 25/01/2014 22:00 ', 'hh24:mi:ss dd/mm/yyyy') Stoptime
8 DOUBLE)
9. SELECT T.*, Starttime + Lvl / 24
10. OF time T
11, (SELECT LEVEL Lvl
THE DOUBLE 12
13 CONNECT BY LEVEL<>
14 (SELECT MAX (TRUNC ((Stoptime-Starttime) * 24)))
15 AT the time)):
16. WHERE the lvl<= trunc="" (="" (stoptime="" -="" starttime)="" *="">=>
17 ORDER 1, 3
18.
STARTTIME STOPTIME-STARTTIME + LVL/24
----------------------------- ----------------------------- -----------------------------
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 19:00
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 20:00
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 21:00
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 22:00
26 January 2014 01:00 26 January 2014 03:00 January 26, 2014 02:00
26 January 2014 01:00 26 January 2014 03:00 January 26, 2014 03:00
6 selected lines.
-
Need help with a query complex for the production database
Hello again,
I need your help once again, for a query how to show me how long each stage of production is by order.
See examples of data and what I expect.
Thank you all for your help.
We use Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Here the example data tables:
And here's what I expect of my request:CREATE TABLE TABLE_2 ( "ORDER_NR" VARCHAR2 (12) , "PRIORITY" VARCHAR2 (2) , "WO_STEP" VARCHAR2 (1) , "STEP_DATE" DATE ); CREATE TABLE TABLE_1 ( "ORDER_NR" VARCHAR2 (12) PRIMARY KEY , "PRIORITY" VARCHAR2 (2) , "CREATE_DATE" DATE , "ACT_STEP" VARCHAR2 (2) , "STEP_DATE" DATE , "EMPLOYEE" VARCHAR2 (5) , "DESCRIPTION" VARCHAR2 (20) ); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, CREATE_DATE, ACT_STEP, STEP_DATE, EMPLOYEE, DESCRIPTION) VALUES ('1KKA1T205634', '12', TO_DATE('10-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'), 'U', TO_DATE('28-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'), 'W0010', 'CLEAN HOUSE'); INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, CREATE_DATE, ACT_STEP, STEP_DATE, EMPLOYEE, DESCRIPTION) VALUES ('1KKA1Z300612', '12', TO_DATE('08-FEB-13 14:00:00','DD-MON-RR HH24:MI:SS'), 'F', TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'), 'K0052', 'REPAIR CAR'); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'A', TO_DATE('12-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', '5', TO_DATE('13-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'K', TO_DATE('13-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', '5', TO_DATE('13-FEB-13 11:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'K', TO_DATE('13-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', '5', TO_DATE('13-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'C', TO_DATE('14-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'B', TO_DATE('14-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'E', TO_DATE('18-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'F', TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'S', TO_DATE('21-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'R', TO_DATE('21-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1T205634', '12', 'U', TO_DATE('28-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'A', TO_DATE('12-FEB-13 13:52:42','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', '5', TO_DATE('13-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'K', TO_DATE('13-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', '5', TO_DATE('13-FEB-13 11:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'K', TO_DATE('13-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', '5', TO_DATE('13-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'C', TO_DATE('14-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'B', TO_DATE('14-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'E', TO_DATE('18-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS')); INSERT INTO TABLE_2 (ORDER_NR, PRIORITY, WO_STEP, STEP_DATE) VALUES ('1KKA1Z300612', '12', 'F', TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS')); COMMIT;
And now the explanation for the result of the query:SYSDATE 28.Feb.13 14:00 ORDER_NR PRIORITYCREATE_DATE STATUS STATUS_DATE DESCRIPTION AGE_1 AGE_2 WAITNG STEP_A STEP_B STEP_C STEP_5 STEP_K STEP_E STEP_F STEP_S STEP_R 1KKA1T205634 12 10.Feb.13 10:00 U 28.Feb.13 12:00 CLEAN HOUSE 18,083 8,833 2,125 0,833 4,125 0,083 0,750 0,208 2,125 0,666 0,042 7,125 1KKA1Z300612 12 08.Feb.13 14:00 F 20.Feb.13 16:00 REPAIR CAR 20,000 16,042 2,125 0,833 4,125 0,083 0,750 0,208 2,125 0,666
The AGE_1 is the difference in days between the "CREATE_DATE" and if EXSIST L'ETAPE 'U' then STEP_DATE or if the STEP 'U' is not found in TABLE_2 then it should show the difference in days between the "CREATE_DATE' and the 'SYSDATE.
The AGE_2 is the difference in days between the STEP "A" STEP_DATE and IF EXSIST L'ETAPE 'R' then STEP_DATE or if the STEP 'R' is not in TABLE_2 then it should show the difference in days between the "CREATE_DATE' and the 'SYSDATE.
The EXPECTATION is the difference in days between CREATE_DATE and STEP 'A' STEP_DATE
The following columns indicate the days, how long the ORDER_NR remains in these TIMES, if an ORDER_NR comes in the same STEP should be calculated together more than once.
If the ORDER_NR jump a step, it should show a zero in the specific field.
I hope that my explanation is good enough, my English skills are far from good.
Thank you for all your help.
Hosts Reinhard W.Solomon Yakobson says:
Just add the amounts:In fact, you could edit all CASES:
with t2 as ( select t.*, lead(step_date) over(partition by order_nr order by step_date) next_step_date from table_2 t ) select t1.*, nvl( max( case t2.wo_step when 'U' then t2.step_date end ), sysdate ) - t1.create_date age_1, nvl( max( case t2.wo_step when 'R' then t2.step_date end ), sysdate ) - t1.create_date age_2, sum( case when t2.wo_step in ('B','5') then t2.next_step_date - t2.step_date end ) step_b_5, sum( case t2.wo_step when 'C' then t2.next_step_date - t2.step_date end ) step_c, sum( case t2.wo_step when 'K' then t2.next_step_date - t2.step_date end ) step_k, sum( case t2.wo_step when 'E' then t2.next_step_date - t2.step_date end ) step_e, sum( case t2.wo_step when 'F' then t2.next_step_date - t2.step_date end ) step_f, sum( case t2.wo_step when 'S' then t2.next_step_date - t2.step_date end ) step_s, sum( case t2.wo_step when 'R' then t2.next_step_date - t2.step_date end ) step_r from table_1 t1, t2 where t2.order_nr = t1.order_nr group by t1.order_nr, t1.priority, t1.create_date, t1.act_step, t1.step_date, t1.employee, t1.description / ORDER_NR PR CREATE_DA AC STEP_DATE EMPLO DESCRIPTION AGE_1 AGE_2 STEP_B_5 STEP_C STEP_K STEP_E STEP_F STEP_S STEP_R ------------ -- --------- -- --------- ----- ----------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 1KKA1T205634 12 10-FEB-13 U 28-FEB-13 W0010 CLEAN HOUSE 18.0833333 10.9583333 4.875 .083333333 .208333333 2.125 .666666667 .041666667 7.125 1KKA1Z300612 12 08-FEB-13 F 20-FEB-13 K0052 REPAIR CAR 44.252338 44.252338 4.875 .083333333 .208333333 2.125 SQL>
SY.
Maybe you are looking for
-
The contacts app keeps the birthdays I put to the next switching & changing the year 1904... Does anyone else have this problem and how to fix this?
-
iMac won't turn on and stays black
I always use my iMac, but my eoectricity in the office room close automatically and unplugged my iMac. After re-reading the cable in the office, I turned on my Mac and connected successfully, but then my YouTube does not and I typed my whole hand on
-
Trying to update my computer of friends of a full system recovery, but I am unable to get the windows updates to work properly I get an error code (0 x 80190194) how could I fix it its running Windows XP home Edition Version 2002 it has service pack
-
I'll take my 100 (mobile/portable printer) OfficeJet with me a trip to the airline. I do not expect to print in flight, but I didn't check: it would be reasonably safe to put it in my luggage, or what I considered carry-on? There will be problems of
-
What is the difference between SATA and regular cables?
I am a student in the article so I have a small doubtWhat is the difference between sata cables and normal