Help with SQL Query (Subselects)
993527Feb 26 2013 — edited Mar 24 2013Hello Community,
iam a new member in this forum. The first excuse my englisch, my mother language is German.
At my Workplace we have a large Orcle 11g Database with 30 different tables for production control issues.
I try to get a couple of different informations from the database, so i started with SQL Query's, but for this problem i was not able to write an working query.
In this case i have 2 tables:
Table 1:
ID ;ORDER_NR ;DESCRIPTION ;CREATE_DATE
1 ;A500236 ;CLEAN HOUSE ;02/20/2012
2 ;A623555 ;REPAIR CAR ;01/10/2012
3 ;A866944 ;MAINTAIN EQUIPMENT ;02/11/2012
Table 2:
ID ;ORDER_NR ;WO_STEP ;STEP_DATE ;EMPLOYEE
1 ;A500236 ;A ;02/21/2012 ;W0010
2 ;A500239 ;F ;02/21/2012 ;W0010
3 ;A500239 ;S ;02/22/2012 ;W0027
4 ;A500239 ;R ;02/23/2012 ;H0034
5 ;A500239 ;U ;02/25/2012 ;L0099
6 ;A263555 ;A ;01/15/2012 ;G0009
7 ;A263555 ;C ;01/17/2012 ;S0039
8 ;A263555 ;R ;01/18/2012 ;K0059
9 ;A263555 ;U ;01/19/2012 ;A0048
10 ;A866944 ;A ;02/13/2012 ;H0034
11 ;A866944 ;B ;02/13/2012 ;L0035
12 ;A866944 ;G ;02/17/2012 ;D0084
13 ;A866944 ;U ;02/23/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 ;CLEAN HOUSE ;02/20/2012 ;5 ;3 ;1
A623555 ;REPAIR CAR ;01/10/2012 ;42 ;39 ;38
A866944 ;MAINTAIN EQUIPMENT ;02/11/2012 ;15 ;4 ;3
The age of my query result should be calculated from the Create date of the Order.
I want to know 2 things, one is how old was the Order when they reached that status A, R and U.
The second this ist, how long did the order remain on the stat A,R and U (and if possible all other status also)
It could happend that not each order reaches each status, so it ca go directly from A to you in this case i want display a wildcard in this row/column
I hope you all know what i mean and which result i expect.
Thanks for your Help.
Reinhard W.