Summing in hierachical query
Hello
I'm having real problems trying to put together a hierarchical query. I've not really done too much with them before other than really basic stuff, so any help would be greatly appreciated.
I'm trying to set up a structure that will let me represent time windows as part of a batch job controller. Each window can have a parent and can also have multiple dependencies...probably best if I use a diagram:
Main batch
|
|----Data Preparation
| |
| |
| |-----60m
|
|----Thread 1 *Data preparation
| |
| |
| |-----30m
|----Thread 2 *Data preparation
| |
| |
| |-----90m
|----Thread 3 *Data preparation
| |
| |
| |-----180m
|----Thread 4 *Data preparation
| |
| |
| |-----10m
|
|----Reports *Thread 1,2,3,4
| |
| |
| |-----130m
|
|-----11 hoursThis shows that the "Main Batch" window is 11 hours in total. It contains 6 further windows each with their own durations. Each window can also be dependent on the completion of one or more other windows. So in this case, the "Reports" window is owned by the "Main Batch" window, but is dependent on the completion of Threads 1-4. The text in itallics denotes a dependency. Represented another way:
Main batch(11hr)
|
data preparation(1hr)
|
| | | |
thread 1 thread 2 thread 3 thread 4
(30m) (1hr30m) (3hr) (10m)
| | | |
|
Report(2hr10m)To represent this I've got 2 tables and data like so:
CREATE TABLE dt_test_window
( id NUMBER,
label VARCHAR2(30),
duration INTERVAL DAY TO SECOND,
parent_id NUMBER
CREATE TABLE dt_test_window_dependency
( dependent_id NUMBER,
dependee_id NUMBER
INSERT
INTO
dt_test_window
VALUES
( 1,
'Main batch window',
TO_DSINTERVAL('0 11:00:00'),
NULL
INSERT
INTO
dt_test_window
VALUES
( 2,
'Data preparation',
TO_DSINTERVAL('0 01:00:00'),
1
INSERT
INTO
dt_test_window
VALUES
( 3,
'Thread 1',
TO_DSINTERVAL('0 00:30:00'),
1
INSERT
INTO
dt_test_window
VALUES
( 4,
'Thread 2',
TO_DSINTERVAL('0 01:30:00'),
1
INSERT
INTO
dt_test_window
VALUES
( 5,
'Thread 3',
TO_DSINTERVAL('0 03:00:00'),
1
INSERT
INTO
dt_test_window
VALUES
( 6,
'Thread 4',
TO_DSINTERVAL('0 00:10:00'),
1
INSERT
INTO
dt_test_window
VALUES
( 7,
'Thread 0 Reports',
TO_DSINTERVAL('0 02:10:00'),
1
INSERT
INTO
dt_test_window_dependency
VALUES
( 3,
2
INSERT
INTO
dt_test_window_dependency
VALUES
( 4,
2
INSERT
INTO
dt_test_window_dependency
VALUES
( 5,
2
INSERT
INTO
dt_test_window_dependency
VALUES
( 6,
2
INSERT
INTO
dt_test_window_dependency
VALUES
( 7,
3
INSERT
INTO
dt_test_window_dependency
VALUES
( 7,
4
INSERT
INTO
dt_test_window_dependency
VALUES
( 7,
5
INSERT
INTO
dt_test_window_dependency
VALUES
( 7,
6
/What I'd like to do is run a query that will show the duration of each window, and also sum up the intervals for each window that it depends on, and where there are multiple dependencies at the same level, pick the longest duration. This would allow me to put in a start time, and show the expected end time for each stage. For these data I would expect to see
start_time := 12:00
label duration max_end_time
Main batch 11:00:00 23:00
Data preparation 01:00:00 13:00
Thread 1 00:30:00 13:30
Thread 2 01:30:00 14:30
Thread 3 03:00:00 16:00
Thread 4 00:10:00 13:10
Reports 02:10:00 18:10The exected time for the reports to finish would be 18:10 because they depend on threads 1-4. Thread 3 is the longest running so it cannot start until 16:00.
This is the query I have and the result I get, can anyone tell me where I'm going wrong?
tylerd@DEV2> WITH batch AS
2 ( SELECT
3 TO_DATE('23-JAN-2007 12:00:00','DD-MON-YYYY HH24:MI:SS') start_date
4 FROM
5 dual
6 )
7 SELECT
8 id,
9 label,
10 parent_id,
11 batch.start_date + max_duration
12 FROM
13 ( SELECT
14 win.id,
15 win.label,
16 win.parent_id,
17 MAX( ( SELECT
18 SUM_INTERVAL(win_parent.duration)
19 FROM
20 dt_test_window win_parent
21 WHERE
22 win_parent.id = win_dep.dependee_id
23 CONNECT BY
24 PRIOR dependee_id = dependent_id
25 ) + win.duration
26 ) max_duration
27 FROM
28 dt_test_window win,
29 dt_test_window_dependency win_dep
30 WHERE
31 win.id = win_dep.dependent_id(+)
32 GROUP BY
33 win.id,
34 win.label,
35 win.parent_id
36 ),
37 batch
38 ORDER BY
39 id
40 /
ID LABEL PARENT_ID BATCH.START_DATE+MA
1 Main batch window 23/01/2007 23:00:00
2 Data preparation 1 23/01/2007 13:00:00
3 Thread 1 1 23/01/2007 13:30:00
4 Thread 2 1 23/01/2007 14:30:00
5 Thread 3 1 23/01/2007 16:00:00
6 Thread 4 1 23/01/2007 13:10:00
7 Thread 0 Reports 1 23/01/2007 17:10:00<-should be 18:10
7 rows selected.Thank you
David
p.s.
Here's the code for sum_interval:
CREATE OR REPLACE TYPE SumInterval AS OBJECT
( runningSum INTERVAL DAY(9) TO SECOND(9),
Responsible for initialising the aggregation context
STATIC FUNCTION ODCIAggregateInitialize
( actx IN OUT SumInterval
) RETURN NUMBER,
Adds values to the aggregation context - NULLS are ignored
MEMBER FUNCTION ODCIAggregateIterate
( self IN OUT SumInterval,
val IN DSINTERVAL_UNCONSTRAINED
) RETURN NUMBER,
Routine invoked by Oracle to combine two aggregation contexts. This happens when an
aggregate is invoked in parallel
MEMBER FUNCTION ODCIAggregateMerge
( self IN OUT SumInterval,
ctx2 IN SumInterval
) RETURN NUMBER,
Terminate the aggregation context and return the result
MEMBER FUNCTION ODCIAggregateTerminate
( self IN SumInterval,
returnValue OUT DSINTERVAL_UNCONSTRAINED,
flags IN NUMBER
) RETURN NUMBER
CREATE OR REPLACE TYPE BODY SumInterval AS
STATIC FUNCTION ODCIAggregateInitialize
( actx IN OUT SumInterval
) RETURN NUMBER
IS
BEGIN
IF actx IS NULL THEN
actx := SumInterval (INTERVAL '0 0:0:0.0' DAY TO SECOND);
ELSE
actx.runningSum := INTERVAL '0 0:0:0.0' DAY TO SECOND;
END IF;
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateIterate
( self IN OUT SumInterval,
val IN DSINTERVAL_UNCONSTRAINED
) RETURN NUMBER
IS
BEGIN
self.runningSum := self.runningSum + val;
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateTerminate
( self IN SumInterval,
ReturnValue OUT DSINTERVAL_UNCONSTRAINED,
flags IN NUMBER
) RETURN NUMBER
IS
BEGIN
returnValue := self.runningSum;
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateMerge
( self IN OUT SumInterval,
ctx2 IN SumInterval
) RETURN NUMBER
IS
BEGIN
self.runningSum := self.runningSum + ctx2.runningSum;
RETURN ODCIConst.Success;
END;
END;
CREATE OR REPLACE FUNCTION sum_interval
( x DSINTERVAL_UNCONSTRAINED
) RETURN DSINTERVAL_UNCONSTRAINED
PARALLEL_ENABLE
AGGREGATE USING SumInterval;
/
Hello
After some more experimentation I've found that I need to decode the dependent/dependee ids and group on that to get the correct result. Using id 7(Reports) as the starting point
tylerd@DEV2> SELECT
2 win_lookup.parent_id,
3 win_lookup.id,
4 win_dep_lookup.dependent_id,
5 win_dep_lookup.dependee_id,
6 win_lookup.duration,
7 CONNECT_BY_ISLEAF
8 FROM
9 dt_test_window_dependency win_dep_lookup,
10 dt_test_window win_lookup
11 WHERE
12 win_lookup.id = win_dep_lookup.dependee_id
13 START WITH
14 win_dep_lookup.dependent_id=7
15 CONNECT BY
16 PRIOR win_dep_lookup.dependee_id = win_dep_lookup.dependent_id
17 /
PARENT_ID ID DEPENDENT_ID DEPENDEE_ID DURATION CONNECT_BY_ISLEAF
1 3 7 3 +00 00:30:00.000000 0
1 2 3 2 +00 01:00:00.000000 1
1 4 7 4 +00 01:30:00.000000 0
1 2 4 2 +00 01:00:00.000000 1
1 5 7 5 +00 03:00:00.000000 0
1 2 5 2 +00 01:00:00.000000 1
1 6 7 6 +00 00:10:00.000000 0
1 2 6 2 +00 01:00:00.000000 1
8 rows selected.I can see that if I group using decode and CONNECT_BY_ISLEAF like so:
tylerd@DEV2> SELECT
2 DECODE(CONNECT_BY_ISLEAF, 0, win_dep_lookup.dependee_id,win_dep_lookup.dependent_id) grouping_id,
3 SUM_INTERVAL(win_lookup.duration)
4 FROM
5 dt_test_window_dependency win_dep_lookup,
6 dt_test_window win_lookup
7 WHERE
8 win_lookup.id = win_dep_lookup.dependee_id
9 START WITH
10 win_dep_lookup.dependent_id=7
11 CONNECT BY
12 PRIOR win_dep_lookup.dependee_id = win_dep_lookup.dependent_id
13 GROUP BY
14 DECODE(CONNECT_BY_ISLEAF, 0, win_dep_lookup.dependee_id,win_dep_lookup.dependent_id)
15 /
GROUPING_ID SUM_INTERVAL(WIN_LOOKUP.DURATION)
3 +000000000 01:30:00.000000000
4 +000000000 02:30:00.000000000
5 +000000000 04:00:00.000000000
6 +000000000 01:10:00.000000000I get the correct result for each thread. The problem is, when I try to plug this into the main query to select the MAX of these dependencies, I get
tylerd@DEV2> WITH batch AS
2 ( SELECT
3 TO_DATE('23-JAN-2007 12:00:00','DD-MON-YYYY HH24:MI:SS') start_date
4 FROM
5 dual
6 )
7 SELECT
8 id,
9 label,
10 parent_id,
11 batch.start_date + max_duration
12 FROM
13 ( SELECT
14 win.id,
15 win.label,
16 win.parent_id,
17 MAX( ( SELECT
18 SUM_INTERVAL(win_lookup.duration)
19 FROM
20 dt_test_window_dependency win_dep_lookup,
21 dt_test_window win_lookup
22 WHERE
23 win_lookup.id = win_dep_lookup.dependee_id
24 START WITH
25 win_dep_lookup.dependent_id=win.id
26 CONNECT BY
27 PRIOR win_dep_lookup.dependee_id = win_dep_lookup.dependent_id
28 GROUP BY
29 DECODE(CONNECT_BY_ISLEAF, 0, win_dep_lookup.dependee_id,win_dep_lookup.dependent_id)
30 ) + win.duration
31 ) max_duration
32 FROM
33 dt_test_window win,
34 dt_test_window_dependency win_dep
35 WHERE
36 win.id = win_dep.dependent_id(+)
37 GROUP BY
38 win.id,
39 win.label,
40 win.parent_id
41 ),
42 batch
43 ORDER BY
44 id
45 /
MAX( ( SELECT
ERROR at line 17:
ORA-01427: single-row subquery returns more than one rowWhich I do understand, I just don't know how to get round it.
Any ideas?
David
Similar Messages
-
Sum Total in Query Print Layout
Hi, all
I have a report which is created by a query, How can I insert a variable to show the Total Sum in footer.
Thanks
kimmyHai!
see this thread.
Sub totals in PLD
regards,
Thanga Raj.K -
Issues using SUM Function in query
I have pasted two queries Query1 (calculating counts for total_ships and ships_released) and Query2 (calculating the two same counts and then calculating SUM for total_shipments and I am having problem in this)
Query 1:
select b.loc , b.week, b.vvalue2, b.Total_ships, nvl(a.up_date,'None') as datee , nvl( a.ships_rel_total,0) as Total_released
from (
SELECT l.loc , sr1.vvalue1 as Week, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD') as up_date , count(distinct s.ship_id ) as ships_rel_total
FROM ship s, loct l,
ship_num sr1, ship_num sr, ship_stat ss, ship_stat ss1
WHERE ......
Group by l.loc , sr1.vvalue1, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD')
) A,
( SELECT distinct l.loc , sr1.vvalue1 as Week, sr.vvalue2 , count(s.ship_id ) as Total_Ships
FROM ship s, loct l,
ship_num sr1, ship_num sr, ship_stat ss, ship_stat ss1
WHERE ......
Group by c.loc , c.week , c.vvalue2 ) B
where a.loc (+) = b.loc
and a.vvalue2 (+) = b.vvalue2
order by b.loc, b.week , b.vvalue2,a.up_date; Query 1 Output:
*OUTPUT*
LOC WEEK VALUE2 TOTAL_SHIPS DATEE TOtAL_SHIPS_RELEASED
AA 111 BB 12 10-05-12 2
AA 111 BB 12 11-05-12 4
AA 111 CC 2 14-05-12 1Then I added sum function for total_ships and its not giving me result what I need :(
Query 2:
select b.loc , b.week, b.vvalue2, b.sum_ships, nvl(a.up_date,'None') as datee , nvl( a.ships_rel_total,0) as Total_released
from (
SELECT l.loc , sr1.vvalue1 as Week, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD') as up_date , count(distinct s.ship_id ) as ships_rel_total
FROM ship s, loct l,
ship_num sr1, ship_num sr, ship_stat ss, ship_stat ss1
WHERE ......
Group by l.loc , sr1.vvalue1, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD')
) A,
( Select c.loc, c.week , c.vvalue2 , sum(c.total_ships) sum_ships
from
( SELECT distinct l.loc , sr1.vvalue1 as Week, sr.vvalue2 , count(s.ship_id ) as Total_Ships
FROM ship s, loct l,
ship_num sr1, ship_num sr, ship_stat ss, ship_stat ss1
WHERE ......
Group by l.loc , sr1.vvalue1 , sr.vvalue2 ) C
Group by c.loc , c.week , c.vvalue2 ) B
where a.loc (+) = b.loc
and a.vvalue2 (+) = b.vvalue2
order by b.loc, b.week , b.vvalue2,a.up_date; my query is giving me this :(
Query 2 Output:
LOC WEEK VALUE2 *SUM_SHIPS* DATEE TOtAL_SHIPS_RELEASED
AA 111 BB 26 10-05-12 2
AA 111 BB 26 11-05-12 4
AA 111 CC 26 14-05-12 1
But I need a result like this:
LOC WEEK VALUE2 SUM_SHIPS DATEE TOtAL_SHIPS_RELEASED
AA 111 BB 14 10-05-12 2
AA 111 BB 14 11-05-12 4
AA 111 CC 14 14-05-12 1Hi,
It sounds like you have a Fan Trap , where a one-to-many relationship is causing some items to be counted many times.
The usual solution is to compute the aggregates before doing the one-to-many join. Analytic functions may make this simpler.
Sorry, I can't show you exactly how to do it without the exact data.
Post CREATE TABLE and INSERT statements for all tables involved, and also post the results you want from that data (if different from what you've already posted).
Explain, using specific examples, how you get those results from that data.
Simplify the problem as much as possible. If the problem only concerns the total_ships column, then only post the data needed to compute total_ships. This includes all the columns involved in the joins and GROUP BY clauses.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Question about SUM in SQL query
I have a SQL ststement which is listed below along with it's output.
For the NUM_REQ column, I am expecting to get the number 832 because the pm_requirements_table contains 16 records and they all have a frequency of WEEKLY.
16 * 52 = 832. The query returns 12480 which I can see that it is multiplying the 832 by 15 which is the number of entries in the lpm table 16 * 52 * 15 = 12480.
I need the lpm table in there for other reasons, so my question is how can I get it to return 832 and still have the lpm table as part of the query.
Thanks,
George
SQL
SELECT 'NAS WIDE' as target
, 1 as years
, count(distinct lpm.fac_ident) as facilities
, SUM(CASE upper(req.frequency)
WHEN 'DAILY' THEN 365
WHEN 'WEEKLY' THEN 52
WHEN 'MONTHLY' THEN 12
WHEN 'QUARTERLY' THEN 4
WHEN 'SEMIANNUALLY' THEN 2
WHEN 'ANNUALLY' THEN 1
ELSE 0
END) as num_req
FROM lpm, pm_requirements_table req
group by 'NAS WIDE';OUTPUT
"TARGET","YEARS","FACILITIES","NUM_REQ"
"NAS WIDE",1,1,12480
-- PM_REQUIREMENTS_TABLE
"PUBLICATION_ORDER","PUBLICATION_PARAGRAPH_NUMBER","DESCRIPTION","FREQUENCY","CHECK_OR_MAINTENANCE","PRTANTAC_ID"
"6310.19A","161A","Check transmitter average rf power output","WEEKLY","",2
"6310.19A","161B","Check transmitter VSWR","WEEKLY","",3
"6310.19A","161C","Check RMS transmitter pulse width","WEEKLY","",4
"6310.19A","161D(1)","Check filament current","WEEKLY","",5
"6310.19A","161D(2)","Check focus coil current","WEEKLY","",6
"6310.19A","161D(3)","Check Klystron voltage","WEEKLY","",7
"6310.19A","161D(4)","Check Klystron current","WEEKLY","",8
"6310.19A","161D(5)","Check PFN voltage","WEEKLY","",9
"6310.19A","161D(6)","Check vacuum pump current","WEEKLY","",10
"6310.19A","161E","Check target receiver MDS","WEEKLY","",11
"6310.19A","161F","Check target receiver NF","WEEKLY","",12
"6310.19A","161G","Check target receiver recovery","WEEKLY","",13
"6310.19A","161H","Check weather receiver MDS","WEEKLY","",14
"6310.19A","161I","Check weather receiver NF","WEEKLY","",15
"6310.19A","161J","Check weather receiver recovery","WEEKLY","",16
"6310.19A","161K","Check spare modem operation","WEEKLY","",17
-- LPM table
"LOG_ID","FAC_IDENT","FAC_TYPE","CODE_CATEGORY","SUPPLEMENTAL_CODE","MAINT_ACTION_CODE","INTERRUPT_CONDITION","ATOW_CODE","SECTOR_CODE","LOG_STATUS","START_DATE","START_DATETIME","END_DATE","END_DATETIME","MODIFIED_DATETIME","WR_AREA","SHORT_NAME","EQUIPMENT_IDENT","INTERVAL_CODE","EARLIEST_DATE","EARLIEST_DATETIME","SCHEDULED_DATE","SCHEDULED_DATETIME","LATEST_DATE","LATEST_DATETIME","WR_CREW_UNIT","WR_WATCH","PUBLICATION_ORDER","PUBLICATION_ORDER_ORIGINAL","PUBLICATION_PARAGRAPH","PUBLICATION_PARAGRAPH_ORIGINAL","NUMBER_OF_TASKS","LOG_SUMMARY","COMMENTS","RELATED_LOGS","LPMANTAC_ID"
108305902,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",07-MAY-10,"05/07/2010 3:24",07-MAY-10,"05/07/2010 3:28","05/07/2010 3:31","RADAR","SYS","SYSTEM","W","05/02/2010","05/02/2010 0:00",05-MAY-10,"05/05/2010 0:00",08-MAY-10,"05/08/2010 0:00","RADR","","6310.19A","6310.19A","161.K","161. K","1","","","",1
108306002,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",02-MAY-10,"05/02/2010 21:00",02-MAY-10,"05/02/2010 21:30","05/03/2010 1:07","RADAR","SYS","CHAN B","W","05/02/2010","05/02/2010 0:00",05-MAY-10,"05/05/2010 0:00",08-MAY-10,"05/08/2010 0:00","RADR","","6310.19A","6310.19A","161A-J","161 A-J","15","","","",2
108306102,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",02-MAY-10,"05/02/2010 21:00",02-MAY-10,"05/02/2010 21:30","05/03/2010 1:07","RADAR","SYS","CHAN A","W","05/02/2010","05/02/2010 0:00",05-MAY-10,"05/05/2010 0:00",08-MAY-10,"05/08/2010 0:00","RADR","","6310.19A","6310.19A","161A-J","161 A-J","15","","","",3
104188702,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",29-APR-10,"4/29/2010 10:09",29-APR-10,"4/29/2010 10:11","4/29/2010 10:30","RADAR","SYS","SYSTEM","W","4/25/2010","4/25/2010 0:00",28-APR-10,"4/28/2010 0:00",01-MAY-10,"05/01/2010 0:00","RADR","","6310.19A","6310.19A","161.K","161. K","1","","","",4
104188402,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",26-APR-10,"4/26/2010 13:33",26-APR-10,"4/26/2010 13:46","4/26/2010 15:23","RADAR","SYS","CHAN A","W","4/25/2010","4/25/2010 0:00",28-APR-10,"4/28/2010 0:00",01-MAY-10,"05/01/2010 0:00","RADR","","6310.19A","6310.19A","161A-J","161 A-J","15","","","",5
104188502,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",26-APR-10,"4/26/2010 13:33",26-APR-10,"4/26/2010 13:46","4/26/2010 15:23","RADAR","SYS","CHAN B","W","4/25/2010","4/25/2010 0:00",28-APR-10,"4/28/2010 0:00",01-MAY-10,"05/01/2010 0:00","RADR","","6310.19A","6310.19A","161A-J","161 A-J","15","","","",6
101223702,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",19-APR-10,"4/19/2010 1:30",19-APR-10,"4/19/2010 2:10","4/19/2010 3:12","RADAR","SYS","CHAN B","W","4/18/2010","4/18/2010 0:00",21-APR-10,"4/21/2010 0:00",24-APR-10,"4/24/2010 0:00","RADR","","6310.19A","6310.19A","161A-J","161 A-J","15","","","",7
101223802,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",19-APR-10,"4/19/2010 1:30",19-APR-10,"4/19/2010 2:10","4/19/2010 3:12","RADAR","SYS","CHAN A","W","4/18/2010","4/18/2010 0:00",21-APR-10,"4/21/2010 0:00",24-APR-10,"4/24/2010 0:00","RADR","","6310.19A","6310.19A","161A-J","161 A-J","15","","","",8
101223602,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",19-APR-10,"4/19/2010 1:00",19-APR-10,"4/19/2010 1:09","4/19/2010 3:12","RADAR","SYS","SYSTEM","W","4/18/2010","4/18/2010 0:00",21-APR-10,"4/21/2010 0:00",24-APR-10,"4/24/2010 0:00","RADR","","6310.19A","6310.19A","161.K","161. K","1","","","",9
96642602,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",12-APR-10,"04/12/2010 10:25",12-APR-10,"04/12/2010 10:34","04/12/2010 17:49","RADAR","SYS","SYSTEM","W","04/11/2010","04/11/2010 0:00",14-APR-10,"4/14/2010 0:00",17-APR-10,"4/17/2010 0:00","RADR","","6310.19A","6310.19A","161.K","161. K","1","","","",10
96642402,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",11-APR-10,"04/11/2010 11:10",11-APR-10,"04/11/2010 11:15","04/11/2010 12:51","RADAR","SYS","CHAN B","W","04/11/2010","04/11/2010 0:00",14-APR-10,"4/14/2010 0:00",17-APR-10,"4/17/2010 0:00","RADR","","6310.19A","6310.19A","161A-J","161 A-J","15","","","",11
96642302,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",11-APR-10,"04/11/2010 11:05",11-APR-10,"04/11/2010 11:10","04/11/2010 12:51","RADAR","SYS","CHAN A","W","04/11/2010","04/11/2010 0:00",14-APR-10,"4/14/2010 0:00",17-APR-10,"4/17/2010 0:00","RADR","","6310.19A","6310.19A","161A-J","161 A-J","15","","","",12
92805502,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",07-APR-10,"04/07/2010 18:10",07-APR-10,"04/07/2010 18:22","04/07/2010 19:04","RADAR","SYS","CHAN A","W","04/04/2010","04/04/2010 0:00",07-APR-10,"04/07/2010 0:00",10-APR-10,"04/10/2010 0:00","RADR","","6310.19A","6310.19A","161A-J","161 A-J","15","","","",13
92805402,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",07-APR-10,"04/07/2010 17:53",07-APR-10,"04/07/2010 18:05","04/07/2010 19:04","RADAR","SYS","CHAN B","W","04/04/2010","04/04/2010 0:00",07-APR-10,"04/07/2010 0:00",10-APR-10,"04/10/2010 0:00","RADR","","6310.19A","6310.19A","161A-J","161 A-J","15","","","",14
92805302,"ATL","ASR",50,"0","P","","WEQ1C","SO1LB","C",07-APR-10,"04/07/2010 9:55",07-APR-10,"04/07/2010 10:05","04/07/2010 10:29","RADAR","SYS","SYSTEM","W","04/04/2010","04/04/2010 0:00",07-APR-10,"04/07/2010 0:00",10-APR-10,"04/10/2010 0:00","RADR","","6310.19A","6310.19A","161.K","161. K","1","","","",15Edited by: George Heller on Jul 15, 2011 10:32 AM-- LPM
CREATE TABLE "LPM"
"LOG_ID" NUMBER(22,0) NOT NULL ENABLE,
"FAC_IDENT" VARCHAR2(5),
"FAC_TYPE" VARCHAR2(5),
"CODE_CATEGORY" NUMBER(22,0) NOT NULL ENABLE,
"SUPPLEMENTAL_CODE" VARCHAR2(1),
"MAINT_ACTION_CODE" VARCHAR2(1),
"INTERRUPT_CONDITION" VARCHAR2(22),
"ATOW_CODE" VARCHAR2(22),
"SECTOR_CODE" VARCHAR2(5),
"LOG_STATUS" VARCHAR2(3) NOT NULL ENABLE,
"START_DATE" DATE,
"START_DATETIME" VARCHAR2(22),
"END_DATE" DATE,
"END_DATETIME" VARCHAR2(22),
"MODIFIED_DATETIME" VARCHAR2(22),
"WR_AREA" VARCHAR2(6),
"SHORT_NAME" VARCHAR2(15),
"EQUIPMENT_IDENT" VARCHAR2(15),
"INTERVAL_CODE" VARCHAR2(255),
"EARLIEST_DATE" VARCHAR2(4000),
"EARLIEST_DATETIME" VARCHAR2(255),
"SCHEDULED_DATE" DATE,
"SCHEDULED_DATETIME" VARCHAR2(22),
"LATEST_DATE" DATE,
"LATEST_DATETIME" VARCHAR2(22),
"WR_CREW_UNIT" VARCHAR2(10),
"WR_WATCH" VARCHAR2(1),
"PUBLICATION_ORDER" VARCHAR2(30),
"PUBLICATION_ORDER_ORIGINAL" VARCHAR2(30),
"PUBLICATION_PARAGRAPH" VARCHAR2(30),
"PUBLICATION_PARAGRAPH_ORIGINAL" VARCHAR2(30),
"NUMBER_OF_TASKS" VARCHAR2(25),
"LOG_SUMMARY" VARCHAR2(255),
"COMMENTS" CLOB,
"RELATED_LOGS" CLOB,
"LPMANTAC_ID" NUMBER,
PRIMARY KEY ("LPMANTAC_ID") ENABLE
CREATE UNIQUE INDEX "SYS_IL0000077142C00035$$" ON "LPM"
-- LPM_PARAGRAPH_MAPPING
CREATE TABLE "LPM_PARAGRAPH_MAPPING_TABLE"
"PUBLICATION_ORDER" VARCHAR2(30),
"PUBLICATION_PARAGRAPH" VARCHAR2(30),
"PARAGRAPH_ALIAS_MAPPING" VARCHAR2(30),
"LPMTANTAC_ID" NUMBER,
PRIMARY KEY ("LPMTANTAC_ID") ENABLE
CREATE UNIQUE INDEX "SYS_C0011587" ON "LPM_PARAGRAPH_MAPPING_TABLE"
"LPMTANTAC_ID"
-- PM_REQUIREMENTS_TABLE
CREATE TABLE "PM_REQUIREMENTS_TABLE"
"PUBLICATION_ORDER" VARCHAR2(30),
"PUBLICATION_PARAGRAPH_NUMBER" VARCHAR2(30),
"DESCRIPTION" VARCHAR2(4000),
"FREQUENCY" VARCHAR2(30),
"CHECK_OR_MAINTENANCE" VARCHAR2(22),
"PRTANTAC_ID" NUMBER,
PRIMARY KEY ("PRTANTAC_ID") ENABLE
CREATE UNIQUE INDEX "SYS_C0011588" ON "PM_REQUIREMENTS_TABLE"
"PRTANTAC_ID"
REM INSERTING into LPM
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (108305902,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('07-MAY-10','DD-MON-RR'),'05/07/2010 3:24',to_date('07-MAY-10','DD-MON-RR'),'05/07/2010 3:28','05/07/2010 3:31','RADAR','SYS','SYSTEM','W','05/02/2010','05/02/2010 0:00',to_date('05-MAY-10','DD-MON-RR'),'05/05/2010 0:00',to_date('08-MAY-10','DD-MON-RR'),'05/08/2010 0:00','RADR',null,'6310.19A','6310.19A','161.K','161. K','1',null,1);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (108306002,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:00',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:30','05/03/2010 1:07','RADAR','SYS','CHAN B','W','05/02/2010','05/02/2010 0:00',to_date('05-MAY-10','DD-MON-RR'),'05/05/2010 0:00',to_date('08-MAY-10','DD-MON-RR'),'05/08/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null,2);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (108306102,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:00',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:30','05/03/2010 1:07','RADAR','SYS','CHAN A','W','05/02/2010','05/02/2010 0:00',to_date('05-MAY-10','DD-MON-RR'),'05/05/2010 0:00',to_date('08-MAY-10','DD-MON-RR'),'05/08/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null,3);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (104188702,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('29-APR-10','DD-MON-RR'),'4/29/2010 10:09',to_date('29-APR-10','DD-MON-RR'),'4/29/2010 10:11','4/29/2010 10:30','RADAR','SYS','SYSTEM','W','4/25/2010','4/25/2010 0:00',to_date('28-APR-10','DD-MON-RR'),'4/28/2010 0:00',to_date('01-MAY-10','DD-MON-RR'),'05/01/2010 0:00','RADR',null,'6310.19A','6310.19A','161.K','161. K','1',null,4);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (104188402,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:33',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:46','4/26/2010 15:23','RADAR','SYS','CHAN A','W','4/25/2010','4/25/2010 0:00',to_date('28-APR-10','DD-MON-RR'),'4/28/2010 0:00',to_date('01-MAY-10','DD-MON-RR'),'05/01/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null,5);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (104188502,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:33',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:46','4/26/2010 15:23','RADAR','SYS','CHAN B','W','4/25/2010','4/25/2010 0:00',to_date('28-APR-10','DD-MON-RR'),'4/28/2010 0:00',to_date('01-MAY-10','DD-MON-RR'),'05/01/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null,6);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (101223702,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 1:30',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 2:10','4/19/2010 3:12','RADAR','SYS','CHAN B','W','4/18/2010','4/18/2010 0:00',to_date('21-APR-10','DD-MON-RR'),'4/21/2010 0:00',to_date('24-APR-10','DD-MON-RR'),'4/24/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null,7);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (101223802,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 1:30',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 2:10','4/19/2010 3:12','RADAR','SYS','CHAN A','W','4/18/2010','4/18/2010 0:00',to_date('21-APR-10','DD-MON-RR'),'4/21/2010 0:00',to_date('24-APR-10','DD-MON-RR'),'4/24/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null,8);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (101223602,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 1:00',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 1:09','4/19/2010 3:12','RADAR','SYS','SYSTEM','W','4/18/2010','4/18/2010 0:00',to_date('21-APR-10','DD-MON-RR'),'4/21/2010 0:00',to_date('24-APR-10','DD-MON-RR'),'4/24/2010 0:00','RADR',null,'6310.19A','6310.19A','161.K','161. K','1',null,9);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (96642602,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('12-APR-10','DD-MON-RR'),'04/12/2010 10:25',to_date('12-APR-10','DD-MON-RR'),'04/12/2010 10:34','04/12/2010 17:49','RADAR','SYS','SYSTEM','W','04/11/2010','04/11/2010 0:00',to_date('14-APR-10','DD-MON-RR'),'4/14/2010 0:00',to_date('17-APR-10','DD-MON-RR'),'4/17/2010 0:00','RADR',null,'6310.19A','6310.19A','161.K','161. K','1',null,10);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (96642402,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:10',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:15','04/11/2010 12:51','RADAR','SYS','CHAN B','W','04/11/2010','04/11/2010 0:00',to_date('14-APR-10','DD-MON-RR'),'4/14/2010 0:00',to_date('17-APR-10','DD-MON-RR'),'4/17/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null,11);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (96642302,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:05',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:10','04/11/2010 12:51','RADAR','SYS','CHAN A','W','04/11/2010','04/11/2010 0:00',to_date('14-APR-10','DD-MON-RR'),'4/14/2010 0:00',to_date('17-APR-10','DD-MON-RR'),'4/17/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null,12);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (92805502,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 18:10',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 18:22','04/07/2010 19:04','RADAR','SYS','CHAN A','W','04/04/2010','04/04/2010 0:00',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 0:00',to_date('10-APR-10','DD-MON-RR'),'04/10/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null,13);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (92805402,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 17:53',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 18:05','04/07/2010 19:04','RADAR','SYS','CHAN B','W','04/04/2010','04/04/2010 0:00',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 0:00',to_date('10-APR-10','DD-MON-RR'),'04/10/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null,14);
Insert into LPM (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,LPMANTAC_ID) values (92805302,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 9:55',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 10:05','04/07/2010 10:29','RADAR','SYS','SYSTEM','W','04/04/2010','04/04/2010 0:00',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 0:00',to_date('10-APR-10','DD-MON-RR'),'04/10/2010 0:00','RADR',null,'6310.19A','6310.19A','161.K','161. K','1',null,15);
REM INSERTING into PM_REQUIREMENTS_TABLE
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161A','Check transmitter average rf power output','WEEKLY',null,2);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161B','Check transmitter VSWR','WEEKLY',null,3);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161C','Check RMS transmitter pulse width','WEEKLY',null,4);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(1)','Check filament current','WEEKLY',null,5);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(2)','Check focus coil current','WEEKLY',null,6);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(3)','Check Klystron voltage','WEEKLY',null,7);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(4)','Check Klystron current','WEEKLY',null,8);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(5)','Check PFN voltage','WEEKLY',null,9);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(6)','Check vacuum pump current','WEEKLY',null,10);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161E','Check target receiver MDS','WEEKLY',null,11);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161F','Check target receiver NF','WEEKLY',null,12);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161G','Check target receiver recovery','WEEKLY',null,13);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161H','Check weather receiver MDS','WEEKLY',null,14);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161I','Check weather receiver NF','WEEKLY',null,15);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161J','Check weather receiver recovery','WEEKLY',null,16);
Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161K','Check spare modem operation','WEEKLY',null,17);
REM INSERTING into LPM_PARAGRAPH_MAPPING_TABLE
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161A','161',26);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161A','161A-J',27);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161B','161',28);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161B','161A-J',29);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161',30);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161A-J',31);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161(A-->K)',32);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161(A-K)',33);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161.(A-C).',34);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(1)','161',35);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(1)','161161 A-J',36);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(1)','161(A-->K)',37);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(1)','161(A-D)',38);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(2)','161',39);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(2)','161 A-J',40);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(2)','161(A-->K)',41);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161E','161E/H',42);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161F','161E/H',43);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161G','161E/H',44);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161H','161E/H',45);
Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161K','161.K',46);Edited by: George Heller on Jul 15, 2011 11:09 AM -
Hi All,
I have Account and amount in my BEx query, Where accounts will start with X or Y or Z. user will enter any of the accounts.
In my output I want see X accounts (assumin that all accounts starting with X belongs to X group, Y belongs to Y group and so on) sum in one row and Y accounts amount sum one more row and so on...
I do not have account group in my flow and dont want to be derived in data flow based on account. Thanks
Please helpe me to achive the same .
Regards,
J Bhi,
You can define 3 RKF which is built on amount and account.
in each the account restriction will change, the restriction will be on a range such as X00001 - X99999 , Y00000 - Y999999 etc.
Now create a structure for the report and use the created RKF's to show the data in format you want to show.
regards,
Arvind. -
Hi,
How to get sum of quantity from each table based on Recipe Id from Raw Material Preparation table.
Ex: Raw material preparation table can have multiple records in Vacuum mixing table like wise Vacuum mixing table can have multiple records in Material filling table.
Thank you,Syed's query does not look correct to me. It is rarely right to have the columns contained in aggregate functions also in the GROUP BY clause.
But to say what is correct, i would suggest that you post:
1) CREATE TABLE statements for your tables, including key decklarations.
2) INSERT statemetns with sample data.
3) The desired result given the sample.
4). Which version of SQL Server you are using.
This makes it simple to copy and paste into a query window to create a tested solution.
Erland Sommarskog, SQL Server MVP, [email protected] -
Recursive, hierachical query problem
Hi!
I have a hierachical SQL query using "connect by" that result in the following dataset (simplified to get down to the point):
ID | Parent | IsData
A | | N
A1 | A | N
A2 | A | N
X1 | A2 | Y
B | | N
B1 | B | N
X2 | B1 | Y
B2 | B | N
C | | N
C1 | C | N There are data entries (X1 and X2) and structural (An, Bn, Cn) entries. Some nodes of the structure tree have data entries as childs, some do not.
What I need is a third column that says "this node has a data node below recursively" as shown below:
ID | Parent | IsData | HasRecursiveDataChilds
A | | N | Y
A1 | A | N | N
A2 | A | N | Y
X1 | A2 | Y | Y/N (doesn't matter)
B | | N | Y
B1 | B | N | Y
X2 | B1 | Y | Y/N (doesn't matter)
B2 | B | N | N
C | | N | N
C1 | C | N | N I currently do this on the client side, after I got all the data, which involves interating through the complete dataset at least once (if you know the data well). Since the data has to be accessed from another (web) app, I want to move the logic to the server.
I'm wondering if this can be done with a simple SQL statement without using PL/SQL to iterate through the result set "manually". I can use the 10g feature set. Performance is not utterly important, so wild sub-sub-subqueries would be ok.
Thanks for your help,
MarcusOk, this is a bit of a fudge..
SQL> ed
Wrote file afiedt.buf
1 with t as (select 'A' as ID, null as parent, 'N' as IsData from dual union all
2 select 'A1','A','N' from dual union all
3 select 'A2','A','N' from dual union all
4 select 'X1','A2','Y' from dual union all
5 select 'B', null, 'N' from dual union all
6 select 'B1','B','N' from dual union all
7 select 'X2','B1','Y' from dual union all
8 select 'B2','B','N' from dual union all
9 select 'C',null,'N' from dual union all
10 select 'C1','C','N' from dual)
11 -- END OF TEST DATA
12 select lpad(' ',(level-1)*2,' ')||id as id, parent, isdata
13 ,NVL((select max(t2.isdata)
14 from t t2
15 connect by parent = prior id
16 start with parent = t.id),'N') as recursivechilddata
17 from t
18 connect by parent = prior id
19* start with parent is null
SQL> /
ID PARENT ISDATA RECURSIVECHILDDATA
A N Y
A1 A N N
A2 A N Y
X1 A2 Y N
B N Y
B1 B N Y
X2 B1 Y N
B2 B N N
C N N
C1 C N N
10 rows selected.
SQL>Edited by: BluShadow on Apr 9, 2009 10:59 AM
removed redundant code -
How to set aggregation rule (SUM) to a query which uses multiple tables
Hi,
I have a doubt like i have a query .i want to get the sum of few columns in that..how can i achieve it as it joins multiple tables . i am posting the query under this. please help me to resolve this. i need to get summation of column which is marked in bold . i am so sorry to post such a big query.. thanks in advance.
SELECT DISTINCT
SAS.ACCOUNT_MONTH_NO,
SAS.BILL_TO_MAJOR_SALES_CHANNEL,
SAS.BUS_AREA_ID,
SAS.CUST_NAME,
SAS.PART_NO,
SAS.PART_DESC,
SAS.PRODUCT_CLASS_CODE,
SAS.SUPER_FAMILY_CODE,
*SAS.NET_SALES_AMT_COA_CURR,*
*SAS.GROSS_SALES_AMT_COA_CURR*,
*SAS.SHIPPED_QTY*,
SAS.SRCE_SYS_ID,
GWS.SRC_LOCATION,
GWS.PART_CF_PART_NUMBER,
GWS.ANALYST_COMMENTS,
NVL(GWS.CLAIM_QUANTITY,0) AS *CLAIM_QUANTITY*,
GWS.CUSTOMER_CLAIM_SUBMISSION_DATE,
GWS.CLAIM_TYPE,
GWS.CREDIT_MEMO_NO,
NVL(GWS.CREDIT_MEMO_AMT,0) AS *CREDIT_MEMO_AMT*,
GWS.TRANS_CREATED_BY,
GWS.COMPONENT_CODE,
GWS.DATE_OF_THE_FAILURE,
GWS.DATE_PART_IN_SERVICE,
GWS.PROBLEM_CODE,
NVL(GWS.TOT_AMT_REVIEWED_BY_CA,0) AS *TOT_AMT_REVIEWED_BY_CA*,
GWS.REGION
FROM
SELECT
TO_CHAR(A.STATUS_DATE, 'YYYYMM') AS ACCOUNT_MONTH_NO,
A.LOCATION_ID SRC_LOCATION,
A.CF_PN PART_CF_PART_NUMBER,
A.ANALYST_COMMENTS,
A.CLAIM_QUANTITY,
A.CUST_CLAIM_SUBM_DATE CUSTOMER_CLAIM_SUBMISSION_DATE,
A.CLAIM_TYPE,
A.CREDIT_MEMO_NO,
A.CREDIT_MEMO_AMT,
A.CREATED_BY TRANS_CREATED_BY,
A.FAULT_CODE COMPONENT_CODE,
A.PART_FAILURE_DATE DATE_OF_THE_FAILURE,
A.PART_IN_SERVICE_DATE DATE_PART_IN_SERVICE,
A.FAULT_CODE PROBLEM_CODE,
A.TOT_AMT_REVIEWED_BY_CA,
A.PART_BUS_AREA_ID AS BUS_AREA_ID,
A.PART_SRC_SYS_ID,
C.CUST_NAME,
C.BILL_TO_MAJOR_SALES_CHANNEL,
P.PART_NO,
P.PART_DESC,
P.PRODUCT_CLASS_CODE,
L.REGION
FROM
EDWOWN.MEDW_BIS_DTL_FACT A,
EDWOWN.EDW_MV_DB_CUST_DIM C,
EDWOWN.EDW_BUSINESS_LOCATION_DIM L,
EDWOWN.EDW_V_ACTV_PART_DIM P
WHERE
A.PART_KEY = P.PART_KEY
AND A.CUSTOMER_KEY = C.CUSTOMER_KEY
AND A.LOCATION_KEY = L.LOCATION_KEY
AND A.PART_SRC_SYS_ID = 'SOMS'
AND A.PART_BUS_AREA_ID = 'USA'
AND C.BILL_TO_MAJOR_SALES_CHANNEL <> 'IN'
GWS,
SELECT
A.ACCOUNT_MONTH_NO,
A.BUS_AREA_ID,
A.NET_SALES_AMT_COA_CURR,
A.GROSS_SALES_AMT_COA_CURR,
A.SHIPPED_QTY,
B.BILL_TO_MAJOR_SALES_CHANNEL,
A.SRCE_SYS_ID,
B.CUST_NAME,
D.PART_NO,
D.PART_DESC,
D.PRODUCT_CLASS_CODE,
D.SUPER_FAMILY_CODE
FROM
SASOWN.SAS_V_CORP_SHIP_FACT A,
SASOWN.SAS_V_CORP_CUST_DIM B,
SASOWN.SAS_V_CORP_LOCN_DIM C,
SASOWN.SAS_V_CORP_PART_DIM D
WHERE
C.DIVISION_CODE = A.DIVISION_CODE
AND
B.B_HIERARCHY_KEY = A.B_HIERARCHY_KEY
AND
D.PART_NO = A.PART_NO
AND
A.SRCE_SYS_ID = 'SOMS'
AND
A.BUS_AREA_ID = 'USA'
AND
B.BILL_TO_MAJOR_SALES_CHANNEL <> 'IN'
SAS
WHERE
SAS.ACCOUNT_MONTH_NO = GWS.ACCOUNT_MONTH_NO(+)
AND SAS.BILL_TO_MAJOR_SALES_CHANNEL = GWS.BILL_TO_MAJOR_SALES_CHANNEL(+)
AND SAS.BUS_AREA_ID = GWS.BUS_AREA_ID(+)
AND SAS.PRODUCT_CLASS_CODE = GWS.PRODUCT_CLASS_CODE(+);thanks in advance
aswinYou get rid of the distinct.
You put sum() around your starred items.
You put all the remaining columns in a GROUP BY clause.
You hope that that none of the other tables has more than one row that matches the SAS table, which would cause you to count that row more than once. -
How to sum up this query (AR reports)
Hi ,
in my rdf ..my main query is..
select
rcta.trx_number invoice_number
,hp.party_name party_name
,rcta.trx_date invoice_date
,rcta.term_due_date invoice_due_date
,rcta.invoice_currency_code transaction_currency
,rctt.name transaction_type
,acr.receipt_number Receipt_number
,acr.receipt_date receipt_date
,NVL(acr.amount,0) Received_amount
,SUM(NVL(RCTL.EXTENDED_AMOUNT,0)) INVOICE_AMT
,sum(NVL(rctl.amount_due_remaining,rctl.extended_amount)) due_amt
,sum(NVL(rctl.extended_amount,0)* decode(gb.currency_code,rcta.invoice_currency_code,1,
(select gl.conversion_rate
from gl_daily_rates gl
where gl.from_currency=rcta.invoice_currency_code
and gl.to_currency=gb.currency_code
and gl.conversion_date=rcta.trx_date))) func_inv_amt
,sum(NVL(rctl.amount_due_remaining,rctl.extended_amount)* decode(gb.currency_code,rcta.invoice_currency_code,1,
(select gl.conversion_rate
from gl_daily_rates gl
where gl.from_currency=rcta.invoice_currency_code
and gl.to_currency=gb.currency_code
and gl.conversion_date=rcta.trx_date))) func_amt_due
,NVL(acr.amount*NVL(acr.exchange_rate,1) ,0) func_rcv_amt
,hps.party_site_number site_num
, hca.account_number account_num
,hl.address1,hl.address2,hl.city,hl.postal_code,hl.state,hl.country
,HCA.CUST_ACCOUNT_ID
,xep.NAME legal_entity
,DECODE(ACRHA.STATUS,'CONFIRMED','Yes','REMITTED','Yes') UNCLR_STATUS
from
ra_customer_trx_all rcta, hz_cust_site_uses_all hcsua,hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa, hz_party_sites hps
,ar_cash_receipt_history_all acrha
,hz_customer_profiles hcp,
ra_cust_trx_types_all rctt
,hr_operating_units hou
,ar_collectors ac
,ra_salesreps_all rsa
, ar_lookups al
,ra_customer_trx_lines_all rctl
,xle_entity_profiles xep
,ar_cash_receipts_all acr
,hz_locations hl
,hz_parties hp
,gl_sets_of_books gb
,ar_payment_schedules_all apsa
,ar_payment_schedules_all apsa1
,AR_RECEIVABLE_APPLICATIONS_ALL ARAA
where HCA.CUST_ACCOUNT_ID = RCTA.SOLD_TO_CUSTOMER_ID
and RCTA.BILL_TO_SITE_USE_ID = HCSUA.SITE_USE_ID
and HCSUA.CUST_ACCT_SITE_ID = HCASA.CUST_ACCT_SITE_ID
and rcta.customer_trx_id = rctl.customer_trx_id
and hcasa.party_site_id = hps.party_site_id
and hca.cust_account_id =hcp.cust_account_id(+)
and HCP.COLLECTOR_ID= AC.COLLECTOR_ID (+)
AND hou.organization_id (+)= rcta.org_id
and HCA.PARTY_ID = HP.PARTY_ID
and RCTA.CUST_TRX_TYPE_ID = RCTT.CUST_TRX_TYPE_ID
and RCTA.ORG_ID = RCTT.ORG_ID
and RCTA.PRIMARY_SALESREP_ID=RSA.SALESREP_ID(+)
and hca.customer_type=al.lookup_code
and al.lookup_type='CUSTOMER_TYPE'
and al.enabled_flag = 'Y'
AND hou.default_legal_context_id=xep.legal_entity_id
and sysdate between NVL(AL.START_DATE_ACTIVE,sysdate) and NVL(AL.END_DATE_ACTIVE,sysdate)
and HL.LOCATION_ID = HPS.LOCATION_ID
and RCTA.SET_OF_BOOKS_ID=GB.SET_OF_BOOKS_ID
/*AND xep.NAME =NVL(:p_legal_entity,xep.NAME)
AND hou.NAME BETWEEN NVL(:p_oper_unit_low,hou.NAME) AND NVL(:p_oper_unit_high,hou.NAME)
AND TRUNC(rcta.trx_date) <= TRUNC(TO_DATE(TO_CHAR(:p_as_of_date,'RRRR/MM/DD HH24:MI:SS'),'RRRR/MM/DD HH24:MI:SS'))
AND DECODE(:p_sales_rep_low,NULL,1,rsa.name) BETWEEN DECODE(:p_sales_rep_low,NULL, 1,:p_sales_rep_low) AND DECODE(:p_sales_rep_high,NULL, 1,:p_sales_rep_high)
and hp.party_name between NVL(:p_cust_name_low, hp.party_name) and NVL(:p_cust_name_high,hp.party_name)
AND hp.party_number between NVL(:p_cust_num_low, hp.party_number) and NVL(:p_cust_num_high, hp.party_number)
AND hca.account_number between NVL(:p_cust_accnt_low, hca.account_number) and NVL(:p_cust_accnt_high, hca.account_number)
AND hps.party_site_number BETWEEN NVL(:p_cust_accnt_site_low, hps.party_site_number) and NVL(:p_cust_accnt_site_high, hps.party_site_number)
AND rctt.name=NVL(:p_transaction_class,rctt.name)
AND hca.customer_class_code = NVL(:p_classification, hca.customer_class_code)
AND ac.name BETWEEN NVL(:p_collector_name_low,ac.name) and NVL(:p_collector_name_high,ac.name)
AND al.meaning=NVL(:p_account_type,al.meaning)*/
and RCTA.CUSTOMER_TRX_ID=APSA.CUSTOMER_TRX_ID(+)
and APSA1.CASH_RECEIPT_ID(+)=ACR.CASH_RECEIPT_ID
and ACRHA.CASH_RECEIPT_ID = ACR.CASH_RECEIPT_ID(+)
and ACRHA.CASH_RECEIPT_HISTORY_ID(+) = ARAA.CASH_RECEIPT_HISTORY_ID
and ACRHA.CASH_RECEIPT_ID(+) = ARAA.CASH_RECEIPT_ID
and RCTA.CUSTOMER_TRX_ID = ARAA.APPLIED_CUSTOMER_TRX_ID(+)
--&CP_UNC_RECPT
GROUP BY rcta.trx_number
,rcta.trx_date
,rcta.term_due_date
,rcta.invoice_currency_code
,rctt.name
,acr.receipt_number
,acr.receipt_date
,acr.amount
,hps.party_site_number
, hca.account_number
,hl.address1,hl.address2,hl.city,hl.postal_code,hl.state,hl.country,hca.cust_account_id,hp.party_name
,acr.amount*NVL(acr.exchange_rate,1)
,xep.NAME
,DECODE(ACRHA.STATUS,'CONFIRMED','Yes','REMITTED','Yes')
order by RCTA.TRX_NUMBER;
I am using a summary column to sum up the due_amt at currency level.
My requirement is ..i need to sum up due_amt only for distinct values of invoice numberi didnot understand how to use the partition properly..
for your further information
As u can see from the query my output will have columns invoice_number and due_amt,
my requirement is when one invoice has multiple receipts(for example 2 ),then in both the rows due_amt will be same
so while summing up the due_amt in summary column the same amount is calculated twice , so i need it to be calculated only once for one invoice number
if there is only one receipt for a invoice then it is working fine ... -
I need help please with the following query.
I have a table that contains a currency, voucher, start_date and a value.
Data in the tables looks like this:
GB, 31/05/2010, A, 100
GB, 31/05/2010, B, 250
GB, 31/05/2010, A, 72
GB, 12/12/2009, A, 1000
GB, 12/12/2009, B, 72
LX, 12/05/2010, A, 90
This is where it gets complicated, I need to show the total(SUM) value when the start_date < 60 days from sysdate and also when the start_date > 61 days AND only if the voucher = A and partioned by the currency.
So, in other words I need my results like this.
GB, 31/05/2010, A, 100, *172, 0*
GB, 31/05/2010, B, 250, *0, 0*
GB, 31/05/2010, A, 72, *172, 0*
GB, 12/12/2009, A, 1000, *0, 1000*
GB, 12/12/2009, B, 72, *0, 0*
LX, 12/05/2010, A, 90, *90, 0*
The bold columns are what I need, one called less_than and one more_than.
A big big thank you and any advice I appreciate.
SPlease make a habit of posting sample data we can work with right away by using CREATE TABLE and INSERT INTO statements, or use the WITH clause as shown below:
SQL> with t as ( -- generating sample data:
2 select 'GB' currency, to_date('31/05/2010', 'dd/mm/yyyy') start_date, 'A' voucher, 100 value from dual union
3 select 'GB', to_date('31/05/2010', 'dd/mm/yyyy'), 'B', 250 from dual union
4 select 'GB', to_date('31/05/2010', 'dd/mm/yyyy'), 'A', 72 from dual union
5 select 'GB', to_date('12/12/2009', 'dd/mm/yyyy'), 'A', 1000 from dual union
6 select 'GB', to_date('12/12/2009', 'dd/mm/yyyy'), 'B', 72 from dual union
7 select 'LX', to_date('12/05/2010', 'dd/mm/yyyy'), 'A', 90 from dual
8 )
9 --
10 -- actual query:
11 --
12 select currency
13 , start_date
14 , voucher
15 , value
16 , sum(case
17 when trunc(sysdate-start_date)< 60
18 and voucher = 'A'
19 then value
20 else 0
21 end) over (partition by currency, voucher, start_date) sum_val1
22 , sum(case
23 when trunc(sysdate-start_date)> 61
24 and voucher = 'A'
25 then value
26 else 0
27 end) over (partition by currency, voucher, start_date) sum_val2
28 from t;
CU START_DAT V VALUE SUM_VAL1 SUM_VAL2
GB 12-DEC-09 A 1000 0 1000
GB 31-MAY-10 A 72 172 0
GB 31-MAY-10 A 100 172 0
GB 12-DEC-09 B 72 0 0
GB 31-MAY-10 B 250 0 0
LX 12-MAY-10 A 90 90 0
6 rows selected. -
Sum() in select query
Hi,
How to avoid getting empty row when sum() function returns no value if the condition fails in where clause?
TIA
HarishSQL> select sum(cnt) sm
2 from t;
SM
SQL> select sum(cnt) sm
2 from t
3 minus
4 select null sm
5 from dual;
no rows selected -
URGENT PLS!!
hi,
pls im trying to query my database but i dont know how to write the query. here is what i was told to do.
there are 3 tables,
1. HCP table that hold all the name of hospitals (primary key is HCP_ID)
2. EMPLOYEE table, which hold the info about employee (primary key is EMP_ID and foreign key is HCP_ID)
3.DEPENDANT table which hold info about the families(dependants) of an EMPLOYEE (primary key is DEP_ID, foreign key is EMP_ID)
now my boss wants a report on the hospitals(HCP) that have 1-499 number of lives.(lives, i mean employee and dependant) which should include the name of the hospital and the count of lives in each hospital as the only 2 colunm. thanks
Edited by: tiana on Jul 11, 2011 3:17 AMSomething like this;
select h.HCP_Name as Hospital_Name
,e.cn as Number_of_Lives
from HCP h
,(select e.hcp_id
,count(1) over (partition by e.hcp_id) cn
from Employees e
,Dependant d
where e.Emp_ID = d.Emp_ID) e
where e.cn > 0 and e.cn < 500
and h.hcp_id = e.hcp_id
/Edited by: bluefrog on Jul 11, 2011 11:42 AM -
Hi,
I have one query Master child relation
SELECT D.code DM.CASE
FROM D , DM
WHERE D.PF = '1'
AND D.CODE = DM.PARENT_CODE
ORDER BY 1
I want a output for master code 1 times and multiple recoed from child multiles times
1 10000
20000
2 30000
40000
3 50000
60000
70000
Like these.
Pls help its very urgent
Thanks
ReenaIt's not a problem if you'll use Elic's example properely:
SQL> SELECT lag(null, 1, d.dname)
2 over (partition by e.deptno order by e.ename) as dname,
3 e.ename
4 from
5 emp e, dept d
6 where e.deptno = d.deptno
7 ORDER BY D.dname, e.ename
8 /
DNAME ENAME
ACCOUNTING CLARK
KING
MILLER
RESEARCH ADAMS
FORD
JONES
SCOTT
SMITH
SALES ALLEN
BLAKE
JAMES
MARTIN
TURNER
WARD
14 rows selected.Rgds. -
Hi
I have some columns, I put 4 columns that I want build a Hierachal tree
CD_TP_Strut
CD_Strut
CD_TP_Strut_Parent
CD_Strut_Parent
How can I to use Connect by ?
Examples data of my table
I have some columns, I put 4 columns that I want build a Hierachal tree
CD_TP_Strut
CD_Strut
CD_TP_Strut_Parent
CD_Strut_Parent
ExamplesCD_TP_Strut CD_Strut CD_TP_Strut_Parent CD_Strut_Parent
0 1 NULL NULL
1 1 0 1
2 1 1 1
3 1 2 1
4 1 3 26
5 1 4 16
Message was edited by:
muttleychess
Message was edited by:
muttleychessI still think that you labeled the columns
incorrectly in your example data, but here goes:
START WITH CD_TP_Strut_Parent is null
AND CD_Strut_Parent is null
CONNECT BY prior CD_TP_Strut = CD_TP_Strut_Parent
AND prior CD_Strut = CD_Strut_ParentReally , Edited labels column -
"SUM" keyword does not show results in query manager
Im using the sql keyword sum in my query which displays sum of doctotal for all sales order created by a particular sales employee.. but it is just showing the doctotal row wise. Is there sum limitations on the sql syntax that can be used?
Also is it possible to show the sum of doctotals without callin it at row level,as we are printing redundant data. Im not using PLD as the requirement is just to show the result of the query.
Please help
Regards
ArisTry the query as
select sum(t.total) from
SELECT T0.DocNum, T0.DocTotal,T0.DocTotal - T0.VatSum, T0.DocDate, Sum(T0.DocTotal) as Total,Sum(T0.DocTotal - T0.VatSum) as withoutTax FROM ORDR T0 INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode
WHERE T1.SlpName ='Rajesh Nair' and T1.SlpCode -1
GROUP BY T0.DocNum, T0.DocDate, T0.VatSum, T0.DocTotal
) t
or in one query at the end as sum as
SELECT T0.DocNum, T0.DocTotal,T0.DocTotal - T0.VatSum, T0.DocDate, Sum(T0.DocTotal) as Total,Sum(T0.DocTotal - T0.VatSum) as withoutTax FROM ORDR T0 INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode
WHERE T1.SlpName ='Rajesh Nair' and T1.SlpCode -1
GROUP BY T0.DocNum, T0.DocDate, T0.VatSum, T0.DocTotal
UNION
select null, null, null, null, sum(t.total), null from
SELECT T0.DocNum, T0.DocTotal,T0.DocTotal - T0.VatSum, T0.DocDate, Sum(T0.DocTotal) as Total,Sum(T0.DocTotal - T0.VatSum) as withoutTax FROM ORDR T0 INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode
WHERE T1.SlpName ='Rajesh Nair' and T1.SlpCode -1
GROUP BY T0.DocNum, T0.DocDate, T0.VatSum, T0.DocTotal
) t
Maybe you are looking for
-
When i create billing document - error in account determination
Hi All, When i m going for release the accounting document there is an error "Error in account determination: table T030K key 1000 MW4" Please give the solution ASAP. Thanks, Suresh.
-
Can't Install WAAS in WAVE 574
Hi, When I turn on WAVE 574, it said "No system disk/ disk error" (something like that). So I assume, there is no OS installed in the disk. I downloaded WAAS 4.4.1 rescue CD, and after a while, It said, "Can't determine boot device! Platform initiali
-
Can free apps be downloaded when restrictions are on?
Can my grandson order free applications when restriction are on? I want him to be able to play but not to be able to order expensive apps (he is 6 years old).
-
Hi, Is there any way to use remap_data option of 11g's expdp in 10g, or Is there any way to use 11g's expdp executable in 10g Kind Regards..
-
Cannot get my mail says i am not connected to server
I cannot get my mail. i think this is basic info I need something about server! Can anyone help me. I am not computer literate.