Group by, rollup, best report structure
hi all,
table structure
code varchar2(10);
level_one varchar2(10);
level_two varchar2(10);
level three varchar2(10);
level_four varchar2(10);
level_five varchar2(10);
level_six varchar2(10);
code_level varchar2(5);
code_nat varchar2(5);
value_1 number;
value_2 number;
code type number;
e.g code=1118, level_one = 01, level_two = 1,level_three=11,level_four=111, level_five=1118, level_six=null, value_1 =10,value_2=20,code_level=4
code= 1119, level_one = 01, level_two = 1,level_three=11,level_four=111, level_five=1119 ,level_six=null, value_1 =30,value_2=40,code_level=4
code= 1120, level_one = 01, level_two = 1,level_three=11,level_four=112, level_five=1121, level_six=null, value_1 =0,value_2=90,code_level=4
code= 1139, level_one = 01, level_two = 1,level_three=11,level_four=112, level_five=1139, level_six=null, value_1 =80,value_2=90,code_level=4
code= 1139, level_one = 01, level_two = 1,level_three=11,level_four=112, level_five=1139, level_six=null, value_1 =0,value_2=90,code_level=4
report should show
01
1
11
111
1118 10 20
1119 30 40
total of 111 40 50
112
1120 0 90
1139 80 180 ---- sum(value_2) of code 1139
total of 112 80 270
total of 11 120 320
total of 1 120 320
total of 01 120 320
thanks in advancce
SQL> SELECT
2 a.language,
3 a.count,
4 LPAD(TO_CHAR(ROUND(RATIO_TO_REPORT(SUM(a.count)) OVER
5 (partition by grouping_id(a.language, a.count)) * 100 ,2), '999.99') || '%',20,' ')
6 AS "PERCENTAGE"
7 FROM
8 (SELECT 'English' AS "LANGUAGE", 1 AS "COUNT" FROM DUAL
9 UNION ALL
10 SELECT 'French', 3 FROM DUAL
11 UNION ALL
12 SELECT 'Klingon', 1 FROM DUAL
13 ) a
14 GROUP BY ROLLUP(a.language, a.count)
15 ORDER BY a.language, a.count
16 /
LANGUAG COUNT PERCENTAGE
English 1 20.00%
English 20.00%
French 3 60.00%
French 60.00%
Klingon 1 20.00%
Klingon 20.00%
100.00%
7 linhas selecionadas.
SQL>
Similar Messages
-
Oracle 10g Reports: Control Break using Group By Rollup
Oracle 10g Contol-Break Reporting
Hello. I am trying to create a report using Group By Rollup. The report should look like:
MONTH......._WEEK_..... CODE.... TOTAL
JULY..........WEEK 1..... K1...........2
............................. K1...........2
.............................SUB:.........4
................WEEK 2..... K1...........2
............................. K1...........2
.............................SUB:.........4
...............WEEK 3..... K1...........2
............................. K1...........2
.............................SUB:.........4
...............WEEK 4..... K1...........2
............................. K1...........2
.............................SUB:.........4
..........................MTH Tot:.....16
AUG..........WEEK 1..... K1...........2
............................. K1...........2
.............................SUB:.........4
................WEEK 2..... K1...........2
............................. K1...........2
.............................SUB:.........4
...............WEEK 3..... K1...........2
............................. K1...........2
.............................SUB:.........4
...............WEEK 4..... K1...........2
............................. K1...........2
.............................SUB:.........4
..........................MTH Tot:.....16
..........................GRND TOT: 32
Not sure how to group the codes into the correct month/week and the labels are a problem. Here is the table/data and a my poor attempt at using the Group by rollup. I'm still working on it but any help would be very nice.
create table translog
ttcd VARCHAR2(5) not null,
stime TIMESTAMP(6) not null,
etime TIMESTAMP(6)
insert into translog ( TTCD, STIME, ETIME)
values ('T4', '01-JUL-12 12.00.01.131172 AM', '01-JUL-12 12.00.16.553256 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T4', '01-JUL-12 12.00.17.023083 AM', '01-JUL-12 12.00.37.762118 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('K2', '01-JUL-12 12.00.38.262408 AM', '01-JUL-12 12.00.40.686331 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('U1', '01-JUL-12 12.00.40.769385 AM', '01-JUL-12 12.00.41.281300 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('SK4', '08-JUL-12 12.00.41.746175 AM', '08-JUL-12 12.00.51.775487 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '08-JUL-12 12.00.53.274039 AM', '08-JUL-12 12.00.53.802800 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1','08-JUL-12 12.00.54.340423 AM', '08-JUL-12 12.01.03.767422 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '08-JUL-12 12.01.04.699631 AM', '08-JUL-12 12.01.04.744194 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('S2', '15-JUL-12 12.01.04.796472 AM', '15-JUL-12 12.01.04.817773 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '15-JUL-12 12.01.04.865641 AM', '15-JUL-12 12.01.05.154274 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '15-JUL-12 12.01.05.200749 AM', '15-JUL-12 12.01.05.508953 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '15-JUL-12 12.01.06.876433 AM', '15-JUL-12 12.01.07.510032 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '15-JUL-12 12.01.07.653582 AM', '15-JUL-12 12.01.07.686764 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('S2', '15-JUL-12 12.01.07.736894 AM', '15-JUL-12 12.01.08.163321 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '22-JUL-12 12.01.08.297696 AM', '22-JUL-12 12.01.08.562933 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '22-JUL-12 12.01.08.583805 AM', '22-JUL-12 12.01.08.620702 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '22-JUL-12 12.01.08.744821 AM', '22-JUL-12 12.01.08.987524 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '22-JUL-12 12.01.09.096695 AM', '22-JUL-12 12.01.09.382138 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '22-JUL-12 12.01.09.530122 AM', '22-JUL-12 12.01.10.420257 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '01-AUG-12 12.01.10.550234 AM', '01-AUG-12 12.01.10.581535 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('S2', '01-AUG-12 12.01.10.628756 AM', '01-AUG-12 12.01.10.656373 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '01-AUG-12 12.01.10.740711 AM', '01-AUG-12 12.01.10.768745 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '01-AUG-12 12.01.10.819635 AM', '01-AUG-12 12.01.10.900849 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '01-AUG-12 12.01.09.530122 AM', '01-AUG-12 12.01.10.420257 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '08-AUG-12 12.01.11.231004 AM', '08-AUG-12 12.01.24.073071 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '08-AUG-12 12.01.24.202920 AM', '08-AUG-12 12.01.24.244538 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('S2', '08-AUG-12 12.01.24.292334 AM', '08-AUG-12 12.01.24.318852 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '08-AUG-12 12.01.24.362643 AM', '08-AUG-12 12.01.24.397662 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1','15-AUG-12 12.01.09.530122 AM', '15-AUG-12 12.01.10.420257 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1', '15-AUG-12 12.01.24.414572 AM', '15-AUG-12 12.01.24.444615 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L2W', '15-AUG-12 12.01.24.478739 AM', '15-AUG-12 12.01.25.020265 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('K4', '15-AUG-12 12.01.25.206721 AM', '15-AUG-12 12.01.25.729493 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '15-AUG-12 12.01.25.784746 AM', '15-AUG-12 12.01.39.226921 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1','15-AUG-12 12.01.39.517953 AM', '15-AUG-12 12.01.50.775295 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '22-AUG-12 12.01.57.676446 AM', '22-AUG-12 12.01.58.252945 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '22-AUG-12 12.01.09.530122 AM', '22-AUG-12 12.01.10.420257 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '22-AUG-12 12.01.58.573242 AM', '22-AUG-12 12.02.10.651922 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('L1', '22-AUG-12 12.02.11.209305 AM', '22-AUG-12 12.02.24.140456 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('SK4','22-AUG-12 12.02.25.204035 AM', '22-AUG-12 12.02.25.580603 AM');
insert into translog ( TTCD, STIME, ETIME)
values ('T1','22-AUG-12 12.02.25.656474 AM', '22-AUG-12 12.02.25.689249 AM');
select
decode(grouping(trunc(stime)),1, 'Grand Total: ', trunc(stime)) AS "DATE"
,decode(grouping(ttcd),1, 'SUB TTL:', ttcd) CODE,count(*) TOTAL
from translog
group by rollup (trunc(stime),ttcd);}
Thank you.830894 wrote:
Oracle 10g Contol-Break Reporting
Hello. I am trying to create a report using Group By Rollup. The report should look like:Couple of things:
1) Your test data setup dows not match with your expected output &
2) layout of data (like control break) should ideally be carried out using reporting tools
Here is what you are probably looking for:
SQL> select * from v$version ;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> create table translog
2 (
3 ttcd VARCHAR2(5) not null,
4 stime TIMESTAMP(6) not null,
5 etime TIMESTAMP(6)
6 );
Table created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T4', '01-JUL-12 12.00.01.131172 AM', '01-JUL-12 12.00.16.553256 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T4', '01-JUL-12 12.00.17.023083 AM', '01-JUL-12 12.00.37.762118 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('K2', '01-JUL-12 12.00.38.262408 AM', '01-JUL-12 12.00.40.686331 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('U1', '01-JUL-12 12.00.40.769385 AM', '01-JUL-12 12.00.41.281300 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('SK4', '08-JUL-12 12.00.41.746175 AM', '08-JUL-12 12.00.51.775487 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '08-JUL-12 12.00.53.274039 AM', '08-JUL-12 12.00.53.802800 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1','08-JUL-12 12.00.54.340423 AM', '08-JUL-12 12.01.03.767422 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '08-JUL-12 12.01.04.699631 AM', '08-JUL-12 12.01.04.744194 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('S2', '15-JUL-12 12.01.04.796472 AM', '15-JUL-12 12.01.04.817773 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '15-JUL-12 12.01.04.865641 AM', '15-JUL-12 12.01.05.154274 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '15-JUL-12 12.01.05.200749 AM', '15-JUL-12 12.01.05.508953 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '15-JUL-12 12.01.06.876433 AM', '15-JUL-12 12.01.07.510032 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '15-JUL-12 12.01.07.653582 AM', '15-JUL-12 12.01.07.686764 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('S2', '15-JUL-12 12.01.07.736894 AM', '15-JUL-12 12.01.08.163321 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '22-JUL-12 12.01.08.297696 AM', '22-JUL-12 12.01.08.562933 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '22-JUL-12 12.01.08.583805 AM', '22-JUL-12 12.01.08.620702 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '22-JUL-12 12.01.08.744821 AM', '22-JUL-12 12.01.08.987524 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '22-JUL-12 12.01.09.096695 AM', '22-JUL-12 12.01.09.382138 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '22-JUL-12 12.01.09.530122 AM', '22-JUL-12 12.01.10.420257 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '01-AUG-12 12.01.10.550234 AM', '01-AUG-12 12.01.10.581535 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('S2', '01-AUG-12 12.01.10.628756 AM', '01-AUG-12 12.01.10.656373 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '01-AUG-12 12.01.10.740711 AM', '01-AUG-12 12.01.10.768745 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '01-AUG-12 12.01.10.819635 AM', '01-AUG-12 12.01.10.900849 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '01-AUG-12 12.01.09.530122 AM', '01-AUG-12 12.01.10.420257 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '08-AUG-12 12.01.11.231004 AM', '08-AUG-12 12.01.24.073071 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '08-AUG-12 12.01.24.202920 AM', '08-AUG-12 12.01.24.244538 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('S2', '08-AUG-12 12.01.24.292334 AM', '08-AUG-12 12.01.24.318852 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '08-AUG-12 12.01.24.362643 AM', '08-AUG-12 12.01.24.397662 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1','15-AUG-12 12.01.09.530122 AM', '15-AUG-12 12.01.10.420257 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1', '15-AUG-12 12.01.24.414572 AM', '15-AUG-12 12.01.24.444615 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L2W', '15-AUG-12 12.01.24.478739 AM', '15-AUG-12 12.01.25.020265 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('K4', '15-AUG-12 12.01.25.206721 AM', '15-AUG-12 12.01.25.729493 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '15-AUG-12 12.01.25.784746 AM', '15-AUG-12 12.01.39.226921 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1','15-AUG-12 12.01.39.517953 AM', '15-AUG-12 12.01.50.775295 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '22-AUG-12 12.01.57.676446 AM', '22-AUG-12 12.01.58.252945 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '22-AUG-12 12.01.09.530122 AM', '22-AUG-12 12.01.10.420257 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '22-AUG-12 12.01.58.573242 AM', '22-AUG-12 12.02.10.651922 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('L1', '22-AUG-12 12.02.11.209305 AM', '22-AUG-12 12.02.24.140456 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('SK4','22-AUG-12 12.02.25.204035 AM', '22-AUG-12 12.02.25.580603 AM');
1 row created.
SQL> insert into translog ( TTCD, STIME, ETIME)
2 values ('T1','22-AUG-12 12.02.25.656474 AM', '22-AUG-12 12.02.25.689249 AM');
1 row created.
SQL> commit ;
Commit complete.
SQL> select case when row_number() over (partition by mth order by mth, wk, ttcd) = 1 then mth end as "Month"
2 ,case when row_number() over (partition by mth, wk order by mth, wk, ttcd) = 1 and wk is not null then 'WEEK '||wk end as "Week"
3 ,case when gttcd = 1 and gwk = 0 and gmth = 0 then 'SUB:'
4 when gttcd = 1 and gwk = 1 and gmth = 0 then 'Month Total:'
5 when gttcd = 1 and gwk = 1 and gmth = 1 then 'Grand Total:'
6 else ttcd
7 end as "Code"
8 ,cnt as "Total"
9 from (
10 select trunc(stime, 'MM') as mth, to_char(stime, 'W') as wk, ttcd, count(*) as cnt
11 ,grouping(trunc(stime, 'MM')) as gmth, grouping(to_char(stime, 'W')) as gwk, grouping(ttcd) as gttcd
12 from translog
13 group by rollup(trunc(stime, 'MM'), to_char(stime, 'W'), ttcd)
14 order by trunc(stime, 'MM'), to_char(stime, 'W'), ttcd
15 ) ;
Month Week Code Total
01-JUL-12 WEEK 1 K2 1
T4 2
U1 1
SUB: 4
WEEK 2 L1 2
SK4 1
T1 1
SUB: 4
WEEK 3 L1 1
S2 2
T1 3
SUB: 6
WEEK 4 L1 4
T1 1
SUB: 5
Month Total: 19
01-AUG-12 WEEK 1 L1 1
S2 1
T1 3
SUB: 5
WEEK 2 L1 1
S2 1
T1 2
SUB: 4
WEEK 3 K4 1
L1 3
L2W 1
T1 1
SUB: 6
WEEK 4 L1 4
SK4 1
T1 1
SUB: 6
Month Total: 21
Grand Total: 40
35 rows selected. -
Hierarchical Query with Rollup Sum (CONNECT BY with GROUP BY ROLLUP)
Hi all,
Imagine the following scenario: i have an ACCOUNT table which holds accounts and their hierarchy (currently 5 levels), and a BALANCE table which holds balance records for the accounts. Only CHILD accounts (level 5) have records in the BALANCE table. Simple example:
CREATE TABLE accounts (account_code VARCHAR2(30), parent_account VARCHAR2(30), account_desc VARCHAR2(400));
CREATE TABLE balances (account_code VARCHAR2(30), balance_amount NUMBER(18,2));
INSERT INTO ACCOUNTS VALUES ('TOT',NULL,'Total');
INSERT INTO ACCOUNTS VALUES ('ANA1','TOT','General Expenses');
INSERT INTO ACCOUNTS VALUES ('4801001','ANA1','Small Expenses');
INSERT INTO ACCOUNTS VALUES ('4801002','ANA1','Transportation');
INSERT INTO ACCOUNTS VALUES ('ANA2','TOT','Health Expenses');
INSERT INTO ACCOUNTS VALUES ('4802001','ANA2','Healthcare');
INSERT INTO ACCOUNTS VALUES ('4802002','ANA2','Facilities');
INSERT INTO BALANCES VALUES ('4801001', 2000);
INSERT INTO BALANCES VALUES ('4801002', 1000);
INSERT INTO BALANCES VALUES ('4802001', 3000);
INSERT INTO BALANCES VALUES ('4802002', 4000);What i need in this scenario is to run a hierarchical query, where for each node i compute the sum of all its children (In LEAF nodes which are the child accounts, this sum is the value in BALANCES itself). Final Result would be:
TOT -> 10000
ANA1 -> 3000
4801001 -> 2000
4801001 -> 1000
ANA2 -> 7000
4802001 -> 3000
4802002 -> 4000I have tried various ways, and found out a workaround which works for a fixed amount of levels, basically it builds the hierarchy and computes the SYS_CONNECT_BY_PATH, then splits this as a regular expression and uses GROUP BY ROLLUP to compute the higher levels. Then i assemble it again, now with the computed values. Below is the example query:
select level
, NVL (vfinal.child_account,'TOTAL') ||' - '||
( SELECT account_desc
FROM accounts
WHERE account_code = vfinal.child_acct ) account_name
, to_char(sum_bal, 'fm999g999g999g990') as rolled_up_balance
from
select coalesce( princ.lvl3, princ.lvl2, princ.lvl1 ) child_acct
, DECODE ( princ.lvl2 , NULL
, NULL
, DECODE ( princ.conta_lvl3, NULL
, princ.conta_lvl1,princ.conta_lvl2 ) ) parent_acct
, sum(princ.balance_amount) sum_bal
from (
select hier.lvl1
, hier.lvl2
, hier.lvl3
, hier.parent_account
, hier.account_code child_acc
, bal.balance_amount
from ( select level
, sys_connect_by_path( account_code, '/' ) hierarchy_acct
, REGEXP_SUBSTR(sys_connect_by_path( account_code, '/' ),'[^/]+',1,3) lvl3
, REGEXP_SUBSTR(sys_connect_by_path( account_code, '/' ),'[^/]+',1,2) lvl2
, REGEXP_SUBSTR(sys_connect_by_path( account_code, '/' ),'[^/]+',1,1) lvl1
, account_code
, parent_account
from accounts acc
where level <= 3
start with parent_account is null
connect by nocycle prior account = parent_account
order siblings by parent_account
) hier
, balances bal
where bal.cod_conta = hier.account_code
) princ
where princ.lvl1 is not null
group by rollup ( princ.lvl1
, princ.lvl2
, princ.lvl3 )
order by princ.conta_lvl1
, princ.conta_lvl2
, princ.conta_lvl3
) vfinal
where child_acct is not null
start with parent_acct is null
connect by nocycle prior child_acct = parent_acctAll said and done, what i need is to do the same thing for infinite levels, because this query has 3 fixed levels. Do you know how can i structure a new query where, independently of the number of levels, the parent sums are all rolled up like this?
Thanks a lot in advance! Best Regards!
Thiago
Edited by: Thiago on Sep 6, 2011 11:31 AM
Edited by: Thiago on Sep 6, 2011 1:01 PMHi,
Thiago wrote:
Hi all,
Imagine the following scenario: i have an ACCOUNT table which holds accounts and their hierarchy (currently 5 levels), and a BALANCE table which holds balance records for the accounts. Only CHILD accounts (level 5) have records in the BALANCE table. Simple example:
CREATE TABLE accounts (account_code VARCHAR2(30), parent_account VARCHAR2(30), account_desc VARCHAR2(400));
CREATE TABLE balances (account_code VARCHAR2(30), balance_amount NUMBER(18,2));
INSERT INTO ACCOUNTS ('TOT',NULL,'Total');
INSERT INTO ACCOUNTS ('ANA1','TOT','General Expenses');
INSERT INTO ACCOUNTS ('4801001','ANA1','Small Expenses');
INSERT INTO ACCOUNTS ('4801002','ANA1','Transportation');
INSERT INTO ACCOUNTS ('ANA2','TOT','Health Expenses');
INSERT INTO ACCOUNTS ('4802001','ANA2','Healthcare');
INSERT INTO ACCOUNTS ('4802002','ANA2','Facilities');
INSERT INTO BALANCES ('4801001', 2000);
INSERT INTO BALANCES ('4801001', 1000);
INSERT INTO BALANCES ('4802001', 3000);
INSERT INTO BALANCES ('4802001', 4000);
Thanks for posting the CREATE TABLE and INSERT statements. Remember why you do it: so that the people who want to help you can re-create the problem and test their ideas. If the statments don't work, then they are not so useful. None of the INSERT statements you posted work: they all need a VALUES keyword. Please test those statments before you post them.
Also, make sure that the reuslts you post correspond to the sample data you post. In your sample data, there are no rows in balances for account_codes '4801002' or '4802002'.
I think you want something like this:
WITH connect_by_results AS
SELECT CONNECT_BY_ROOT account_code AS root_account_code
, account_code
FROM accounts
-- NOTE: No START WITH clause
CONNECT BY parent_account = PRIOR account_code
SELECT c.root_account_code || ' -> '
|| TO_CHAR (SUM (b.balance_amount)) AS txt
FROM connect_by_results c
LEFT OUTER JOIN balances b ON c.account_code = b.account_code
GROUP BY c.root_account_code
; -
"Cost Rollup - No Report" not updating costs for some items.
Hi ,
We have an issue with "Cost Rollup - No Report" program. When it is run for all items in an Organization, some item costs were not getting updated.
"Include in Cost Rollup" flag in Master Item form and in Item Costs form is enabled for these items. When we run the report for specific item , it is working fine, cost
is getting updated. Only when we run the report for all items of an org, we are having this issue. Any suggestion or help in this regard is highly appreciated.
Thanks in advance,
Pavan.Hi,
I mean B(Sub Assembly)
Item Rollup Flag
A No
--B Yes
---B1 No
---B2 No
---B3 No
--C Yes
In this case when we run cost rollup by giving item A, Oracle will consider below structure.
A
--C
Regards,
Sarvottam. -
Hi experts,
In my current client we have a requirement for employee reporting structure.
The requirement is one person reporting to maltipal supervisors. is it posible in standard SAP. or if i go for development how it will work how it has to be developed.
please guide me on this.Hi,
Yes, there are ways to do this, but the solution will depend on the outcome you need. You can for example have more than one relationship A012 for your OU (I don't like this one, but I've seen it working). You can use other types os relationships between position and position, I've done that in a customer with relationship B/A 004 and it worked. I've already seen new relationships created in PD in order to represent different types of structure, you can create as many as you want via customize. Everything will depend on the type of structure you want to build. Please be more specific, maybe I can help more.
Best regards,
Thais -
"Cost Rollup - No Report" - allow updates getting flipped to No
Hi ,
We have an issue with "Cost Rollup - No Report" program.
When running the 'Cost Rollup - No Report' job in Oracle for the any cost type, whether it is all items or range of items, the 'allow updates' flag for the that cost type keeps getting flipped in the 'Cost Types' form. The flipping of this flag is preventing us from updating any costs in ERP. Can you please advise why this flag keeps getting flipped so we can prevent in the future?
Thanks in advance,
AbhishekHi,
I mean B(Sub Assembly)
Item Rollup Flag
A No
--B Yes
---B1 No
---B2 No
---B3 No
--C Yes
In this case when we run cost rollup by giving item A, Oracle will consider below structure.
A
--C
Regards,
Sarvottam. -
How to hide Group Tree in Crystal Report Server.
Hi all visitors
i have created one crystal report and my report use group to summary the amount of each day.
after i use group to summary, i used text box cover the group. so my group can't click anything.
After that i upload my report to crystal report server, when i viewed my report and when i click on Group Tree, it will show the list of group (group date in crystal report) and it also can click. I don't want to show the Group Tree in Crystal Report Server.
Anybody know how to hide group tree in crystal report server?
Best Regards,Are you talking custom application, or infoview? If it is custom app, you would have to look at the setToolPanelViewType method. if its infoview, no direct way to change this that i know of.
-
Evaluation Path for Position to Position Reporting Structure
Hello Everyone,
We currently have a position to position reporting structure in place. WIth this being said, not every supervisor in our organization is the chief of a team. I am trying to create an evaluation path that will look at a position, then go up to get the positions report to position (but not go up any further), then go down to get the positions that report to the supervisor. This will allow us to start with a position, then return all the positions that the report to position has. In essence this will allow us to start with a position and get the team (though we don't have an org unit for the team). I am trying to do this for the Team Calendar in ESS.
Below is what I have. The problem is with the depth, if I enter a 2, then it is not getting the lateral positions, but if I enter a 3, then it goes up to another level and gets an additional supervisor (which I do not want).
S A 002 Reports (line) to 2 S
S B 002 Is line supervisor of 1 S
S A 008 Holder 3 P
Has anyone developed and Evaluation Path that does this (gets a positions team without having an org unit) and can offer assistance?
Best Regards,
ScottMy first suggestion was either use Bottoms-up approach or top-down dont use both..like either use either of below
S A 002 Reports (line) or
S B 002 Is line supervisor
but figured u will still have depth issues..so therefore
you cld experiment like below..i understood your requirement, and i am suggesting this totally off-hand thats on top of my head..as i said experiement doing this way..
say you have four levels why dont you use different evalutaion path to link them between each level..
say 1st to 2nd (reports to A002)
2nd to 3rd (subordinate to A005)
3rd to 4th/4th to 3rd (Is line supervisor B 002 )etc
this way you will not have the depth issue as each one is diffeent Ev path..
...oops i can see people laughing at this solution..but well..i tried! -
Dote Line Reporting Structure in OM
Hi Experts
I want to create the Doted Line Reporting structure in OM. Is this relationship type A004- Is subordinate to (disc.). I am confused in this.
Please help me in this.
Thanks
Sheetal GuptaHi Sheetal,
I think In the relationship infotype 1001 you can maintain relationship A/B088 ie dotted line relationship.
But for doing this, I think you need to have a Matrix Organisation.
I think you can go to transaction Code OOVK and maintain 088 relationsip also from there.
More information can be found at Dotted Line relationship in OM
Best Regards,
Venkat.
Edited by: Venkateswara Sarma Bhamidipati on Dec 19, 2010 5:04 AM -
Hi,
I want to create a sample structure for reporting (i.e. Web Intelligence) in IDT.
Details can be seen in the screenshot below.
So far, I found out that derived tables can be used for creating such structures.
However, I'm not sure how to define with mulriple values and also with includes, excludes and groupings.
Can someone suggest a solution and help me with this?
Thanks!Hi Jacqueline,
Thanks for the answer.
Report will only prompt for a date, that's all.
It will be even scheduled with a dynamic date (e.g yesterday).
So, I guess that will not work.
PS : this structure will have more rows. Therefor I can't create tables and bring them together like a single one.
Reporting
Structure
Daily
MTD
YTD
1. Spain (PC)
(Group-3 excluded)
2. Italy (PC
& Tablet)
2.1 Italy (PC & Tablet) (Group-1)
2.1 Italy
(Tablet) (Group-2) -
How use Group By Rollup in BIP ?
Hy everybody ,
I create a dataset with this query :
SELECT cntr.country_region "Region" , cntr.country_name "Pay ", Round(AVG(s.quantity_sold * s.amount_sold ),2) "Moyenne Des Ventes"
FROM customers c inner join sales s
on c.cust_id = s.cust_id
inner join countries cntr
on c.country_id = cntr.country_id
group by rollup (cntr.country_region,cntr.country_name )
It's ok in ad-hoc mode , it's ok when i generate sample data , but when i want to create my Report : I use "Data Table" and for the "Moyenne Des Ventes" column , i have no data.
Someone can help me ?"ROLLUP", "CUBE", "GROUPING SETS" actually I used for ad-hoc reporting only on text based tools. Though in report development tools you can easily generate sub-totals I think you can use different queries.
-
Replicate HR Organisation Management and reporting structure
We have setup the OM and reporting structure in our HR systems. How and in what way can we replicate the same set of data to another ERP client (in a different server)?
Is it via ALE ? What is the objects?
Best Regards,
Grace Chan
65-63607250Hi Grace,
If you intend to transfer the org structure from SAP to SAP, the most effective method is to use ALE:
- You will need to configure the partner profiles of the two systems
- Use the transaction PFAL for a one time initial load
- Set up change pointers for message type HRMD_A
- Run background jobs each night to update the delta changes if you want to keep both systems in sycn.
Hope this helps.
Andrew -
OrgChart 3.0 - Reporting Structure - Portrait View is not showing portrait
Hi,
I have enabled the Reporting Structure in the OrgChart.
Everything works, but the portrait is not showing in the OrgChart when I have selected Portrait view for the position.
Portrait is showing on the Details Panel of the Position.
Portrait is also showing in the Organization Chart (not in Reporting Structure).
This error shows in Reporting Structure:
16 Feb 2011 15:40:59 ERROR com.nakisa.Logger - Hrwpc_Rfc_Ep_Read_Photo_Uri.runEmployeeReadPhotoURI() : Cannot identify key field or value. Whereclause :: (Object_ID='80000001')
16 Feb 2011 15:40:59 WARN com.nakisa.Logger - Detail - CurrentPositionPortrait : FetchData : Could not fetch data for details.
16 Feb 2011 15:40:59 WARN com.nakisa.Logger - Details - ManagerPhoto : Render : Failed because no data is available.
If the position has no PERNR, the log looks like this:
16 Feb 2011 16:14:35 ERROR com.nakisa.Logger - Hrwpc_Rfc_Ep_Read_Photo_Uri.runEmployeeReadPhotoURI() : Cannot identify key field or value. Whereclause :: ( (Pernr is null) or (Pernr='') )
I am guessing could it be the keyword in the WHERE clause that caused the FM in ECC couldn't be called properly.
Anyone else has this problem?Hi Jack,
This function is actually called by the class BAPI_Employee_GetDetails, which is a Nakisa class and not in SAP. Therefore I would raise an OSS note. There are a number of fixes to the SMP build that you have that will be in a build provided by Nakisa.
Best regards,
Luke -
Refreshing subreport data on change of group in the main report
I have created three comma delimited strings in a subreports and then introduced them to the main report. The subreports are simple with no groups. I have one subreport for Authors, one for Departments and one for Schools. This is ok if I filter the data down to one publication. If I remove the filter then I get every instance of each of the subreports. ie all authors in a comma delimited string, all departments and all schools.
I have two groups in the main report, Publication Year (Group #1) and Publication Title (Group #2). This is where I have the problem. The data coming from the subreports show all instances as mentioned above. I want the subreports data to refresh each time the group changes. I need it to only show the necessary comma delimited string for each publication, not every instance.Hi Abhilash,
The logic has worked correctly but the performance is really poor. Is this because I have there subreports doing similar funcitons? Is this a topic for another discussion?
Also, when I try to export the report to xls data only it starts the export but then a msg comes up on the screen relating to the second formula you gave me for comma delimited strings for schools:
SAP Crystal Reports
String length is less than 0 or not an integer.
This relates to the third line in the code:
Left(schools, len(schools)-2);
It then aborts the export. Is this a topic for another discussion also?
Thanks -
S_ALR_87013340-PRCtr Group:plan/Actual Caomparison Report performance issue
I'm trying to get the "actual line item" details from the S_ALR_87013340-PRCtr Group:plan/Actual Caomparison Report and I get a
ABAP run time error. I tried to running for just one month and on several accts. please help to me. how to get the report.
or how to improve the performance of this program.
Thanks in Advancehi,
first we need to know what part of the code is taking time. Do run time analysis using SE30 transaction to know what part of coding is taking more time. use can ST12 transaction to get more detailed analysis.
Since this is standard SAP report also check any OSS note exist for the performance problem.
Maybe you are looking for
-
Channel is not appearing in the container
Hi, i have devloped a channel and also a container. The follwoing are the corresponding xml's. The proble is the channels that i defined as <SELECTED> are not appearing in the container, can any one let me know why?????? arun Channel XML <Channel nam
-
MM Condition type to withholding tax mapping
Hi Folks, I have a query regarding MM and WHT configuration. Can we assign MM condition type to Withholding tax type or WHT Tax type-code combination so that at the time of posting a service based invoice we can identify the service category? Thanks
-
Imbedding a lightroom gallery into my gallery page
How would I embed a flash gallery I've created in Lightroom, into my website gallery page. Candidlovephotography.com
-
ICM_HTTP_CONNECTION_FAILED error in SM59
Hi, I configured ADS and it was working fine with http service. Now i configured SSL in Java and ABAP instances. I need to setup SSL communication between these 2 instances. I did configuration for that but in SM59 when i do connection test for ADS_H
-
After downloading the 64-bit version of iTunes on my Windows 7 machine I get the "Congratulations, you've successfully installed iTunes" message. However, when I plug in my iPhone I get an error message that says, in part, "...the required software