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.
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. -
Want to sort the columns while using GROUP BY ROLLUP.
Want to order the below query using by "News' column in descending order and "Email address" column in Ascending order.
Note: Sorting should not bring Total value to top. It is happening now.
{code}
SELECT decode(grouping(NVL(Client, 'NA')),1, 'Totals', NVL(Client, 'NA')) "Email (Login ID)",
Location "Location",
SUM(News) "News",
SUM(Website) "Website",
FROM VW_FX_USERDATA
GROUP BY ROLLUP (((NVL(Client, 'NA')),Location,1, 'Totals', NVL(Client, 'NA')))
{code}
PLease let me know if you need any details.
Edited by: Nagaraja Akkivalli on Sep 23, 2011 4:04 PMThanks hm,
Let me explain bit clearly.
Say I am getting resultset as below.When I am executing above mentioned query.
Client* Location News Website Total
ABC YD 9 0 4
BCD HB 12 7 13
CDE SI 1 18 3
JNM BI 25 0 4
ZZZ TI 0 221 77
XYZ TT 0 1 1
Totals 47 247 435I want it to as below. Here records are sorted in the descending order of the News Count and then Client*
Client* Location News Website Total
JNM BI 25 0 4
BCD HB 12 7 13
ABC YD 9 0 4
CDE SI 1 18 3
XYZ TT 0 1 1
ZZZ TI 0 221 77
Totals 47 247 435If I order the column by News in the descending order, it is taking Totals value to the top. (Since I am using GROUP BY ROLLUP).
Note: Sorting should not be applied to Totals.
Hope this is clear to you. Let me know if you need any details.
Thanks and Regards
Nagaraja Akkivalli. -
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
; -
Materialized views with GROUP by ROLLUP
I am trying to created Materialized view (snapshot) using group by rollup functionality.
The idea is to use snapshot with all subtotals already calculated in place.
For example average group by rollup (columns of the time dimension).
The idea is to use "query rewrite" Oracle functionality and snapshot with calculated subtotals.
Does anybody have experiance with this method ?
Thank you
MichaelThe query rewrite is an internal function of Oracle. Normally, you have nothing to do than verify that the query that perform OBIEE is rewrited.
In any other way, you can in OBIEE define that you have create an aggregate and OBIEE will (re-)write the query.
http://www.rittmanmead.com/2007/10/26/using-the-obiee-aggregate-persistence-wizard/
Regards
Nico -
Hi
I am using group by rollup ((....)) in order to list my data and then provide a summary at the end.
Please take this example:
with mydata as (
select 'ABC' Part_no, sysdate-10 as Trans_Date, 100 Amount from dual union all
select 'ABC' Part_no, sysdate-10 as Trans_Date, -100 Amount from dual union all
select 'ABD' Part_no, sysdate-10 as Trans_Date, 100 Amount from dual union all
select 'ABD' Part_no, sysdate-10 as Trans_Date, 100 Amount from dual union all
select 'ABE' Part_no, sysdate-10 as Trans_Date, 100 Amount from dual union all
select 'ABE' Part_no, sysdate-10 as Trans_Date, 50 Amount from dual
select
part_no,
trans_date,
sum(amount) total
from
mydata
group by rollup ((part_no, trans_date))The trouble is, in that example, because some rows have no unique identifier, and they are grouped, the are summarised (by nature of group by).
However, I want to retain the detail and also have a summary at the end, as a grand total.
I get:
ABC 5/13/2008 6:10:41 AM 0
ABD 5/13/2008 6:10:41 AM 200
ABE 5/13/2008 6:10:41 AM 150
350I want:
ABC 5/13/2008 6:10:41 AM 100
ABC 5/13/2008 6:10:41 AM -100
ABD 5/13/2008 6:10:41 AM 100
ABD 5/13/2008 6:10:41 AM 100
ABE 5/13/2008 6:10:41 AM 100
ABE 5/13/2008 6:10:41 AM 50
350Can this be done?
ThanksYou can get total something like this:
WITH mydata AS
(SELECT 'ABC' part_no, SYSDATE - 10 AS trans_date, 100 amount
FROM DUAL
UNION ALL
SELECT 'ABC' part_no, SYSDATE - 10 AS trans_date, -100 amount
FROM DUAL
UNION ALL
SELECT 'ABD' part_no, SYSDATE - 10 AS trans_date, 100 amount
FROM DUAL
UNION ALL
SELECT 'ABD' part_no, SYSDATE - 10 AS trans_date, 100 amount
FROM DUAL
UNION ALL
SELECT 'ABE' part_no, SYSDATE - 10 AS trans_date, 100 amount
FROM DUAL
UNION ALL
SELECT 'ABE' part_no, SYSDATE - 10 AS trans_date, 50 amount
FROM DUAL)
SELECT part_no, trans_date, amount, sum (amount) over (partition by 1) total
FROM mydata
PART_NO TRANS_DATE AMOUNT TOTAL
ABC 5/13/2008 1:30:28 AM 100 350
ABC 5/13/2008 1:30:28 AM -100 350
ABE 5/13/2008 1:30:28 AM 50 350
ABD 5/13/2008 1:30:28 AM 100 350
ABE 5/13/2008 1:30:28 AM 100 350
ABD 5/13/2008 1:30:28 AM 100 350
---or
SELECT part_no, trans_date, amount, sum (amount) over (order by part_no) total
FROM mydata -
I am curious if anyone has had this kind of problem. I'm posting a very generic example because the actual
query is very complex and is about 120 lines long. I have the following: An outer query with 2 inline
views as the source for the outer query.
Select a.*, b.*
From
(Select statement from table_a where field3 = '1234' using GROUP BY ROLLUP) a,
(Select statement from table_b where field3 = '1234' using GROUP BY ROLLUP) b,
Where
a.field1 = b.field1 (+) and
a.field2 = b.field2 (+)
The expected results are a one to none, one to one or one to many between a & b.
The results are very inconsistent. For some criteria (eg: field3 = '1234'), I get NO matches
from the second inline view. Others, I get some but not all matches.
If I take each inline view and use them to create tables, then run the outer query by joining the two tables, I get all of the matches.
I'm solving it right now by running each inline view inside of a union query and it performs acceptably, but, I don't understand why I couldn't get the join to work properly.
Has anyone else experienced this ?????a quick one,
SQL>
SQL> With t As
2 (
3 Select 1990 c1,10c2,1000 c3 From dual Union All
4 Select 1991 , 10 ,2000 From dual Union All
5 Select 1990 , 20 ,1500 From dual Union All
6 Select 1991 , 20 ,2500 From dual
7 )Select Case when Grouping(c1) = 1 Then 'Dept Total' Else to_char(c1) End c1,
8 Case When grouping(c2) = 1 Then 'Grand Total' Else to_char(c2) End c2,
9 Sum(c3)
10 From t
11 Group By Rollup(c2,c1)
12 /
C1 C2 SUM(C3)
1990 10 1000
1991 10 2000
Dept Total 10 3000
1990 20 1500
1991 20 2500
Dept Total 20 4000
Dept Total Grand Total 7000
7 rows selected
SQ -
GROUP BY ROLLUP skews RATIO_TO_REPORT
Hi Everyone,
The RATIO_TO_REPORT works fine until I use GROUP BY ROLLUP, then my RATIO_TO_REPORT is incorrrect.
I've tried every combination I can think of.
Any suggestions?
Thank You in Advance for Your Help,
Lou
SELECT
a.language,
a.count,
LPAD(TO_CHAR(ROUND(RATIO_TO_REPORT(SUM(a.count)) OVER () * 100 ,2), '09.99') || '%',20,' ') AS "PERCENTAGE"
FROM
(SELECT 'English' AS "LANGUAGE", 1 AS "COUNT" FROM DUAL
UNION ALL
SELECT 'French', 3 FROM DUAL
UNION ALL
SELECT 'Klingon', 1 FROM DUAL
) a
-- GROUP BY a.language, a.count -- COUNT & PERCENT ARE CORRECT BUT NO COUNT TOTAL
GROUP BY ROLLUP(a.language), a.count -- COUNT AND COUNT TOTAL ARE CORRECT, BUT PERCENT IS SKEWED
ORDER BY a.language, a.countSQL> 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> -
How can I send a message to multiple contacts using "groups".
How can I send a message to multiple contacts using "groups".
It was easy on my sony ericssonn....do i need to download an app?There is no group send option like you are looking for.
To send to a group you have to pick each person you want to send to and send as a group that way. Then don't delete that SMS thread and you can reuse it again later.
As for an app, well SMS works via your carrier and the OS, not something an App can do unless the app send the data to them (a third party) and then they relay it to the carrier. Do you really want to be sending your SMS to some 3rd party first? -
How to use group function in insert or update
Hai All
How can we use group function in insert or update statement
I am generating an attendance so i have different set of timing for example
0800,1200,1230, 1700 and i need to insert into these data into table with min value to intime and max value to
outtime and othere to inertval time in or out
Pls tell me with some example
For example
For INSERT
insert into T2 (barcode,empcode,intime,attend_date)
values(r2.cardn,r2.enpno,MIN(r2.ptime),r2.pdate);
For UPDATE
update dail_att set outtime= MAX(r2.ptime) where empcode=r2.enpno and barcode=r2.cardn and
attend_date=r2.pdate;
Here instead of where i need to use having so pls tell how to use
Thanks & Regards
Srikkanth.MHai Man
R2 is not a table name its a record
Let me explain clearly
I have to generate daily attendance for lot of employees So i have two table t1 and t2
T1 consist of three column empno,date,time
T2 consist of empno,name,date,intime,outtime,intrin,introut
So now i need to give the T1 Min value Of time to T2 Intime and T1 Max value of Time to T2 Outtime fields so there so many records while i am using
max(time) it gives the max value of all so i seperated by group function so now i have an error in subquery ie it is an single row subquery so i need to use multiple row subquery how i can use multiple row subquery in update statement
Thanks In Advance
Srikkanth.M -
How to use group by in PL/SQL
Can anyone give me a clue how to group rows using PL/SQL? I want to make a push button that groups a number of rows. When I run the form and push the button, I get the Oracle 01422 error. I am using one data block and, after pressing execute on the Oracle form in the web browser, I want to sort the rows using the group by clause as a pl sql trigger in a push button (with the WHEN BUTTON PRESSED trigger). I am new to Oracle Forms.
I managed to use a cursor to access and display each row. I have to press the command button I created once for access of each row individually. I want to be able to push the button once, and populate each row with a record from my table. I am using the tabular format. Here is my code:
DECLARE
CURSOR email_message_cur
IS
SELECT sender, subject, body, date_time_sent
FROM Email_Message
ORDER BY sender;
BEGIN
OPEN email_message_cur;
FETCH email_message_cur
INTO :GROUP_EMAIL_MESSAGE.SENDER, :GROUP_EMAIL_MESSAGE.SUBJECT, :GROUP_EMAIL_MESSAGE.BODY, :GROUP_EMAIL_MESSAGE.DATE_TIME_SENT;
WHILE email_message_cur%FOUND LOOP
IF :GROUP_EMAIL_MESSAGE.SENDER IS NOT NULL THEN
CREATE_RECORD;
END IF;
FETCH email_message_cur INTO :GROUP_EMAIL_MESSAGE.SENDER, :GROUP_EMAIL_MESSAGE.SUBJECT, :GROUP_EMAIL_MESSAGE.BODY, :GROUP_EMAIL_MESSAGE.DATE_TIME_SENT;
END LOOP;
CLOSE email_message_cur;
END; -
how to use GROUP BY in ODI tool
Hi ,
you can combine the insert stamt with the select ....so that in the target u will get a single line .....
SQL> select * from prop_details;
PROPERTY RELAVANTD NOTICES
10100 25-JAN-09 30
10100 03-JAN-09 30
10100 02-DEC-08 20
10100 01-DEC-08 10
10100 31-DEC-08 20
10101 10-JAN-09 10
10101 20-JAN-07 15
10101 30-DEC-08 45
10101 20-FEB-08 35
10101 31-JAN-09 25
10 rows selected.
SQL> select PROPERTY,max(RELAVANTDATE),SUM(NOTICES) from PROP_DETAILS GROUP BY P
ROPERTY;
PROPERTY MAX(RELAV SUM(NOTICES)
10101 31-JAN-09 130
10100 25-JAN-09 110
SQL> -
In mdx how to get max date for all employees is it posible shall we use group by in mdx
in mdx how to get max date for all employees is it posible shall we use group by in mdx
example
empno ename date
1 hari 12-01-1982
1 hari 13-06-2000
by using above data i want to get max dataHi Hari3109,
According to your description, you want to get the max date for the employees, right?
In your scenario, do you want to get the max date for all the employees or for each employee? In MDX, we have the Max function to achieve your requirement. You can refer to Naveen's link or the link below to see the details.
http://www.sqldbpros.com/2013/08/get-the-max-date-from-a-cube-using-mdx/
If this is not what you want, please provide us more information about the structure of you cube, so that we can make further analysis.
Regards,
Charlie Liao
TechNet Community Support -
I have 5 rows in the table t.
Id Name Dept Sal
1 AA 10 300
2 BB 10 400
3 CC 20 200
4 DD 20 400
5 EE 30 900
How do I write my SQL Query to get the following output with subtotals & Grand Total?
Id Name Dept Sal
1 AA 10 300
2 BB 10 400
3 CC 20 200
4 DD 20 500
5 EE 30 700
SubTotal 10 700
SubTotal 20 600
SubTotal 30 900
Total 2200
Thanks,
JaySQL> select empno || '-' || ename, deptno, sum(sal)
2 from emp
3 group by rollup(deptno, empno|| '-' || ename)
4 order by deptno nulls last
5 /
EMPNO||'-'||ENAME DEPTNO SUM(SAL)
7782-CLARK 10 2450
7839-KING 10 5000
7934-MILLER 10 1300
10 8750
7369-SMITH 20 800
7566-JONES 20 2975
7788-SCOTT 20 3000
7876-ADAMS 20 1100
7902-FORD 20 3000
20 10875
7499-ALLEN 30 1600
7521-WARD 30 1250
7654-MARTIN 30 1250
7698-BLAKE 30 2850
7844-TURNER 30 1500
7900-JAMES 30 950
30 9400
29025
18 rows selected. -
How can I use group messaging on a iphone 4 ?
I want to use group messaging on my iphone 4.
how do I enable it ?that option doesn't appear on my settings section.
Maybe you are looking for
-
Any one is using K8N Neo MS-7030 with 6600/6800 series with LCD monitor ?
any one is using K8N Neo MS-7030 with 6600/6800 series with LCD monitor and his card is connected through the DVI cable without problems ?
-
Relaunch and optimize taking forever - can I get some realtime help?
I have a large fast system running Vista 64 with 8GB Ram. Suddenly Outlook started running really slow. So I loaded relaunce and optimize. Optimization has been running for more than a half hour using 95 -100% memory. However, only 3 to 5% of CPU is
-
Info object in production server
Can we activate an inffoobject in production server ? how to activate it? thanks in advance
-
N9 help me stop full text message from displaying ...
My full text message is displaying on the bottom of my wallpaper and on a "notifications" screen. How do I stop this ? I only want to read/ see my text when i go into the text area . It is not displaying on the black screen with time . Attachments: t
-
MuVo TX SE 512MB: keep hearing a 'whistling' no
Hi, I just got this MP3 player for myself. I'm very happy with it, except for one thing: when the player changes tracks, it emits this short "whisling" noise... This noise is also heard when the song you're listening to isn't very, how should I say t