Hide duplicate row and analytic functions
Hi all,
I have to count how many customers have two particular product on the same area.
Table cols are:
AREA
PRODUCT_CODE (PK)
CUSTOMER_ID (PK)
QTA
The query is:
select distinct area, count(customer_id) over(PARTITION BY area)
from all_products
where product_code in ('BC01007', 'BC01004')
group by area, customer_id
having ( sum(decode(FPP.PRODOTTO_CODE,'BC01007',qta,0)) ) > 0)
and ( sum(decode(FPP.PRODOTTO_CODE,'BC01004',qta,0)) ) > 0);
In SQL*PLUS works fine, but in Oracle Discoverer I can't get distinct results also if I chek "Hide duplicate rows" in Table Layout .
Anybody have another way to get distinct results for analytic function results?
Thanks in advance,
Giuseppe
The query in Disco is exactly that I've post before.
Results are there:
AREA.........................................C1
01704 - AREA VR NORD..............3
01704 - AREA VR NORD..............3
01704 - AREA VR NORD..............3
01705 - AREA VR SUD.................1
02702 - AREA EMILIA NORD........1
If I check "hide duplicate row" in layout option results didn't change.
If I add distinct clause manually in SQL*PLUS the query become:
SELECT distinct o141151.AREA as E141152,COUNT(o141151.CUSTOMER_ID) OVER(PARTITION BY o141151.AREA ) as C_1
FROM BPN.ALL_PRODUCTS o141151
WHERE (o141151.PRODUCT_CODE IN ('BC01006','BC01007','BC01004'))
GROUP BY o141151.AREA,o141151.CUSTOMER_ID
HAVING (( SUM(DECODE(o141151.PRODUCT_CODE,'BC01006',1,0)) ) > 0 AND ( SUM(DECODE(o141151.PRODUCT_CODE,'BC01004',1,0)) ) > 0)
and the results are not duplicate.
AREA.........................................C1
01704 - AREA VR NORD..............3
01705 - AREA VR SUD.................1
02702 - AREA EMILIA NORD........1
There is any other way to force distinct clause in Discoverer?
Thank you
Giuseppe
Similar Messages
-
Hide duplicate rows in Cross Tab report
where can i find the option to hide duplicate rows in cross tab report..?
Is it a limitation with crosstab report..?
Ok, here's the issue i have a crosstab report and its based on a VIEW.
the data duplicates based on created_by and last_updated_by columns as I'm not using these columns in the report.
any ideas or workarounds to avoid duplicates....?
Thanks! -
GROUP BY and analytical functions
Hi all,
I need your help with grouping my data.
Below you can see sample of my data (in my case I have view where data is in almost same format).
with test_data as(
select '01' as code, 'SM' as abbreviation, 1010 as groupnum, 21 as pieces, 4.13 as volume, 3.186 as avgvolume from dual
union
select '01' as code, 'SM' as abbreviation, 2010 as groupnum, 21 as pieces, 0 as volume, 3.186 as avgvolume from dual
union
select '01' as code, 'SM' as abbreviation, 3000 as groupnum, 21 as pieces, 55 as volume, 3.186 as avgvolume from dual
union
select '01' as code, 'SM' as abbreviation, 3010 as groupnum, 21 as pieces, 7.77 as volume, 3.186 as avgvolume from dual
union
select '02' as code, 'SMP' as abbreviation, 1010 as groupnum, 30 as pieces, 2.99 as volume, 0.1 as avgvolume from dual
union
select '03' as code, 'SMC' as abbreviation, 1010 as groupnum, 10 as pieces, 4.59 as volume, 0.459 as avgvolume from dual
union
select '40' as code, 'DB' as abbreviation, 1010 as groupnum, 21 as pieces, 5.28 as avgvolume, 0.251 as avgvolume from dual
select
DECODE (GROUPING (code), 1, 'report total:', code) as code,
abbreviation as abbreviation,
groupnum as pricelistgrp,
sum(pieces) as pieces,
sum(volume) as volume,
sum(avgvolume) as avgvolume
--sum(sum(distinct pieces)) over (partition by code,groupnum) as piecessum,
--sum(volume) volume,
--round(sum(volume) / 82,3) as avgvolume
from test_data
group by grouping sets((code,abbreviation,groupnum,pieces,volume,avgvolume),null)
order by 1,3;Select statement which I have written returns the output below:
CODE ABBR GRPOUP PIECES VOLUME AVGVOL
01 SM 1010 21 4.13 3.186
01 SM 2010 21 0 3.186
01 SM 3000 21 55 3.186
01 SM 3010 21 7.77 3.186
02 SMP 1010 30 2.99 0.1
03 SMC 1010 10 4.59 0.459
40 DB 1010 21 5.28 0.251
report total: 145 79.76 13.554Number of pieces and avg volume is same for same codes (01 - pieces = 21, avgvolume = 3.186 etc.)
What I need is to get output like below:
CODE ABBR GRPOUP PIECES VOLUME AVGVOL
01 SM 1010 21 4.13 3.186
01 SM 2010 21 0 3.186
01 SM 3000 21 55 3.186
01 SM 3010 21 7.77 3.186
02 SMP 1010 30 2.99 0.1
03 SMC 1010 10 4.59 0.459
40 DB 1010 21 5.28 0.251
report total: 82 79.76 0.973Where total number of pieces is computed as sum of distinct numbers of pieces for each code -> *82 = 21 + 30 + 10 +21*.
Total volume is just sum of volumes in each row -> *79.76 = 4.13+0+55+7.77+2.99+4.59+5.28*.
And Average volume is computed as total volume / total number of pieces -> *0.973 = 79.76 / 82*.
I was trying to use analytical function (sum() over (partition by)) to get desired output, but without good results.
Could anyone help me with this issue?
Thanks in advance!
Regards,
JiriHi, Jiri,
Jiri N. wrote:
Hi all,
I need your help with grouping my data.
Below you can see sample of my data (in my case I have view where data is in almost same format).I assume the view guarantees that all rows with the same code (or the same code and groupnum) will always have the same pieces and the same avgvolume.
with test_data as( ...Thanks for posting this; it's very helpful.
What I need is to get output like below:
CODE ABBR GRPOUP PIECES VOLUME AVGVOL
01 SM 1010 21 4.13 3.186
01 SM 2010 21 0 3.186
01 SM 3000 21 55 3.186
01 SM 3010 21 7.77 3.186
02 SMP 1010 30 2.99 0.1
03 SMC 1010 10 4.59 0.459
40 DB 1010 21 5.28 0.251
report total: 82 79.76 0.973
Except for the last row, you're just displaying data straight from the table (or view).
It might be easier to get the results you want uisng a UNION. One branch of the UNION would get the"report total" row, and the other branch would get all the rest.
>
Where total number of pieces is computed as sum of distinct numbers of pieces for each code -> *82 = 21 + 30 + 10 +21*.It's not just distinct numbers. In this example, two different codes have pieces=21, so the total of distinct pieces is 61 = 21 + 30 + 10.
>
Total volume is just sum of volumes in each row -> *79.76 = 4.13+0+55+7.77+2.99+4.59+5.28*.
And Average volume is computed as total volume / total number of pieces -> *0.973 = 79.76 / 82*.
I was trying to use analytical function (sum() over (partition by)) to get desired output, but without good results. I would use nested aggregate functions to do that:
SELECT code
, abbreviation
, groupnum AS pricelistgrp
, pieces
, volume
, avgvolume
FROM test_data
UNION ALL
SELECT 'report total:' AS code
, NULL AS abbreviaion
, NULL AS pricelistgrp
, SUM (MAX (pieces)) AS pieces
, SUM (SUM (volume)) AS volume
, SUM (SUM (volume))
/ SUM (MAX (pieces)) AS avgvolume
FROM test_data
GROUP BY code -- , abbreviation?
ORDER BY code
, pricelistgrp
;Output:
CODE ABB PRICELISTGRP PIECES VOLUME AVGVOLUME
01 SM 1010 21 4.13 3.186
01 SM 2010 21 0.00 3.186
01 SM 3000 21 55.00 3.186
01 SM 3010 21 7.77 3.186
02 SMP 1010 30 2.99 .100
03 SMC 1010 10 4.59 .459
40 DB 1010 21 5.28 .251
report total: 82 79.76 .973It's unclear if you want to GROUP BY just code (like I did above) or by both code and abbreviation.
Given that this data is coming from a view, it might be simpler and/or more efficient to make separate version of the view, or to replicate most of the view in a query. -
Reports 6i and analytical function
hi
I have this query which wrks fine in TOAD
SELECT rvt.receipt_num srv_no, rvt.supplier supplier,
rvt.transaction_date srv_date, inv.segment1 item_no,
rvt.item_desc item_description, hrov.NAME,
( SUBSTR (v.standard_industry_class, 1, 1)
|| '-'
|| po_headers.segment1
|| '-'
|| TO_CHAR (po_headers.creation_date, 'RRRR')
) po_no,
po_headers.creation_date_disp po_date,
( (rvt.currency_conversion_rate * po_lines.unit_price)
* rvt.transact_qty
)aMOUNT ,
----Analytic function used here
SUM( ( (rvt.currency_conversion_rate * po_lines.unit_price)
* rvt.transact_qty)) over(partition by hrov.NAME) SUM_AMOUNT,
(SELECT SUM (mot.on_hand)
FROM mtl_onhand_total_mwb_v mot
WHERE inv.inventory_item_id = mot.inventory_item_id
-- AND INV.ORGANIZATION_ID=MOT.ORGANIZATION_ID
AND loc.inventory_location_id = mot.locator_id
AND loc.organization_id = mot.organization_id
AND rvt.locator_id = mot.locator_id) onhand
FROM rcv_vrc_txs_v rvt,
mtl_system_items_b inv,
mtl_item_locations loc,
hr_organization_units_v hrov,
po_headers_v po_headers,
ap_vendors_v v,
po_lines_v po_lines
WHERE inv.inventory_item_id(+) = rvt.item_id
AND po_headers.vendor_id = v.vendor_id
AND rvt.po_line_id = po_lines.po_line_id
AND rvt.po_header_id = po_lines.po_header_id
AND rvt.po_header_id = po_headers.po_header_id
AND rvt.supplier_id = v.vendor_id
AND inv.organization_id = hrov.organization_id
AND rvt.transaction_type = 'DELIVER'
AND rvt.inspection_status_code <> 'REJECTED'
AND rvt.organization_id = inv.organization_id(+)
AND to_char(to_date(rvt.transaction_date, 'DD/MM/YYYY'), 'DD-MON-YYYY') BETWEEN (:p_from_date)
AND NVL (:p_to_date,
:p_from_date
AND rvt.locator_id = loc.physical_location_id(+)
AND transaction_id NOT IN (
SELECT parent_transaction_id
FROM rcv_vrc_txs_v rvtd
WHERE rvt.item_id = rvtd.item_id
AND rvtd.transaction_type IN
('RETURN TO RECEIVING', 'RETURN TO VENDOR'))
GROUP BY rvt.receipt_num , rvt.supplier ,
rvt.transaction_date , inv.segment1 ,
rvt.item_desc , hrov.NAME,v.standard_industry_clasS,po_headers.segment1,po_headers.creation_datE,
po_headers.creation_date_disp,inv.inventory_item_iD,loc.inventory_location_id,loc.organization_id,
rvt.locator_iD,rvt.currency_conversion_rate,po_lines.unit_price, rvt.transact_qty
but it gives blank page in reports 6i
could it be that reports 6i donot support analytical functionskindly guide another alternaive
thanking in advance
Edited by: makdutakdu on Mar 25, 2012 2:22 PMhi
will the view be like
create view S_Amount as SELECT rvt.receipt_num srv_no, rvt.supplier supplier,
rvt.transaction_date srv_date, inv.segment1 item_no,
rvt.item_desc item_description, hrov.NAME,
( SUBSTR (v.standard_industry_class, 1, 1)
|| '-'
|| po_headers.segment1
|| '-'
|| TO_CHAR (po_headers.creation_date, 'RRRR')
) po_no,
po_headers.creation_date_disp po_date,
( (rvt.currency_conversion_rate * po_lines.unit_price)
* rvt.transact_qty
)aMOUNT ,
----Analytic function used here
SUM( ( (rvt.currency_conversion_rate * po_lines.unit_price)
* rvt.transact_qty)) over(partition by hrov.NAME) SUM_AMOUNT,
(SELECT SUM (mot.on_hand)
FROM mtl_onhand_total_mwb_v mot
WHERE inv.inventory_item_id = mot.inventory_item_id
-- AND INV.ORGANIZATION_ID=MOT.ORGANIZATION_ID
AND loc.inventory_location_id = mot.locator_id
AND loc.organization_id = mot.organization_id
AND rvt.locator_id = mot.locator_id) onhand
FROM rcv_vrc_txs_v rvt,
mtl_system_items_b inv,
mtl_item_locations loc,
hr_organization_units_v hrov,
po_headers_v po_headers,
ap_vendors_v v,
po_lines_v po_lines
WHERE inv.inventory_item_id(+) = rvt.item_id
AND po_headers.vendor_id = v.vendor_id
AND rvt.po_line_id = po_lines.po_line_id
AND rvt.po_header_id = po_lines.po_header_id
AND rvt.po_header_id = po_headers.po_header_id
AND rvt.supplier_id = v.vendor_id
AND inv.organization_id = hrov.organization_id
AND rvt.transaction_type = 'DELIVER'
AND rvt.inspection_status_code <> 'REJECTED'
AND rvt.organization_id = inv.organization_id(+)
AND rvt.locator_id = loc.physical_location_id(+)
AND transaction_id NOT IN (
SELECT parent_transaction_id
FROM rcv_vrc_txs_v rvtd
WHERE rvt.item_id = rvtd.item_id
AND rvtd.transaction_type IN
('RETURN TO RECEIVING', 'RETURN TO VENDOR'))
GROUP BY rvt.receipt_num , rvt.supplier ,
rvt.transaction_date , inv.segment1 ,
rvt.item_desc , hrov.NAME,v.standard_industry_clasS,po_headers.segment1,po_headers.creation_datE,
po_headers.creation_date_disp,inv.inventory_item_iD,loc.inventory_location_id,loc.organization_id,
rvt.locator_iD,rvt.currency_conversion_rate,po_lines.unit_price, rvt.transact_qtyis this correct ? i mean i have not included the bind parameters in the view ..moreover shoud this view be joined with all the columns in the from clause of the original query?
kindly guide
thanking in advance -
Duplicate rows and data across multiple pages.
My form has 12 pages (each page = 1 month). With a loop, the pages are hidden until the corresponding button is clicked and it becomes visible (Thanks Assure Dynamics for a great solution to a very long form).
In Month 1, I have a table with a repeating row. What I would like to do is copy the repreating row and it's data to Month 2. Then I would like to have the table from Month 2, duplicate to Month 3, Month 3 to Month 4 and so on.
I have been able to get the row from Month 1 to duplicate in Month 2 on the exit event of each cell in the row, however, when you are in Month 2 and do not change a cell which was created in Month 1, the data does not duplicate into the next month (Month 3). Instead of on the exit event of the cell(field), I thought placing it on a button would work but it is not.
This is what I used on the exit event in the table for Month 1:
xfa.resolveNode("Month2.Performancegoals2.updates.details[" + this.parent.index + "]").projectName.rawValue = this.rawValue;
I also thought instead of using a table and a repeating row, I could place the information in a repeating subform but I am still stuck with how to copy the subform and its completed data to the next month.
I am really stuck and have been looking for hours for a solution. Can anyone help, I am out of time for the deadline of this form.?Hi,
Firstly,you must do the count of the table.
frmTableBlock.tblTableMonth2._rowItem.count = frmTableBlock.tblTableMonth1._rowItem.count
frmTableBlock.tblTableMonth12._rowItem.count = frmTableBlock.tblTableMonth1._rowItem.count
And write the code which is do you want to copy the data Month1 to month12.
I hope
S,Candy -
Extract duplicate rows and append them in single column
hi,
my requirement is i have the data in a table like below
GIVEN DATA
req_id res_id
100 200
100 201
101 300
102 200
102 400
102 null
THE OUTPUT SHOULD BE
req_id res_id
100 200,201
101 300
102 200,400
can anybody please help me out in writing the query to get the desired output.
*****NOTE: REMEMBER THERE ARE 100'S OF RECORDS IN THE TABLE THE ABOVE IS ONLY SAMPLE DATA.
Thanks in advance
Best Regards,SQL> with t as
2 (select 100 req_id,200 res_id from dual union all
3 select 100,null from dual union all
4 select 100,201 from dual union all
5 select 100,null from dual union all
6 select 101,null from dual union all
7 select 101,null from dual)
8 select req_id,
9 ltrim(max(sys_connect_by_path(res_id,'-')),'-') res_id
10 from(
11 select req_id,res_id,
12 row_number() over(partition by req_id order by res_id nulls first) rn
13 from t)
14 start with rn = 1
15 connect by rn = prior rn + 1
16 and req_id = prior req_id
17 group by req_id;
REQ_ID RES_ID
100 200-201
101 -
Hierarchy query and analytical functions
Hi I have 2 tables which are
ACCOUNT TBL
ACCOUNT_ID PAYING_ACCOUNT_ID PARENT_ACCOUNT_ID
4571111 4571111 4571111
4571112 4571112 4571111
4571113 4571113 4571111
3995313 3995313 3995313
3996786 3995313 3995313
4008375 3995313 3995313CUSTOMER_STATUS
CUSTOMER_ID CUSTOMER_STATUS
4571111 Active
4571112 Active
4571113 Active
3995313 Active
3996786 Deactive
4008375 Active I need to produce an output like below:
Level_Label ACCOUNT_ID PAYING_ACCOUNT_ID PARENT_ACCOUNT_ID MY_TOTAL_PR_A MY_TOTAL_NPR_A TOTAL_PR_A TOTAL_NPR_A MY_TOTAL_PR_D MY_TOTAL_NPR_D TOTAL_PR_D TOTAL_NPR_D
3995313 3995313 3995313 3995313 0 1 0 1 0 1 0 1
4008375 4008375 3995313 3995313 0 0 0 1 0 0 0 1
3996786 3996786 3995313 3995313 0 0 0 1 0 0 0 1
4571111 4571111 4571111 4571111 2 0 2 0 0 0 0 0
4571112 4571112 4571112 4571111 0 0 2 0 0 0 0 0
4571113 4571113 4571113 4571111 0 0 2 0 0 0 0 0This is the logic and rational to fill-up above fields.
MY_TOTAL_PR_A Sum of all child accounts of current account that are PR (PAYING_ACCOUNT_ID = ACCOUNT_ID) and in sates considered Active.
The current account is not included in the sum, only child accounts
MY_TOTAL_NPR_A Sum of all child accounts of current account that are NPR (PAYING_ACCOUNT_ID != ACCOUNT_ID) and in sates considered Active.
The current account is not included in the sum, only child accounts
TOTAL_PR_A Sum of all accounts of the structure that are PR and in sates considered Active.
The TOP account is not included in the sum, only TOP account childs
TOTAL_NPR_A Sum of all accounts of the structure that are NPR and in sates considered Active.
The TOP account is not included in the sum, only TOP account childs
MY_TOTAL_PR_D Sum of all child accounts of current account that are PR and in sates considered Deactive.
The current account is not included in the sum, only child accounts
MY_TOTAL_NPR_D Sum of all child accounts of current account that are NPR and in sates considered Deactive.
The current account is not included in the sum, only child accounts
TOTAL_PR_D Sum of all accounts of the structure that are PR and in sates considered Deactive.
The TOP account is not included in the sum, only TOP account childs
TOTAL_NPR_D Sum of all accounts of the structure that are NPR and in sates considered Deactive.
The TOP account is not included in the sum, only TOP account childsThis is my code, I managed to calculate the MY_TOTAL_XXX filed but failed to calculate TOTAL_XXX. Appreciate any information / comment. Thanks
WITH got_descendants AS
SELECT CONNECT_BY_ROOT a.account_id AS ancestor_id
, a.paying_account_id
, a.account_id
, a.parent_account_id
, LEVEL AS lvl
, c.customer_status
FROM account a inner join customer_status c
on a.account_id = c.customer_id
CONNECT BY NOCYCLE PRIOR a.account_id = a.parent_account_id
--AND account_id != parent_account_id
), DUMMY2 AS
select g.* from got_descendants g
), DUMMY AS
SELECT ancestor_id
, COUNT (CASE WHEN lvl > 1
AND account_id = paying_account_id
And ancestor_id != account_id
AND customer_status = 'A' THEN 1 END) AS my_total_pr_a
, COUNT (CASE WHEN ancestor_id = paying_account_id
AND customer_status = 'A' THEN 1 END) AS total_pr_a
, COUNT (CASE WHEN lvl > 1
AND account_id != paying_account_id
And ancestor_id != account_id
AND customer_status = 'A' THEN 1 END) AS my_total_npr_a
, COUNT (CASE WHEN ancestor_id != paying_account_id
AND customer_status = 'A'
And ancestor_id != parent_account_id THEN 1 END) AS total_npr_a
, COUNT (CASE WHEN lvl > 1
AND account_id = paying_account_id
And ancestor_id != account_id
AND customer_status = 'D' THEN 1 END) AS my_total_pr_d
, COUNT (CASE WHEN ancestor_id = paying_account_id
AND customer_status = 'D' THEN 1 END) AS total_pr_d
, COUNT (CASE WHEN lvl > 1
AND account_id != paying_account_id
And ancestor_id != account_id
AND customer_status = 'D' THEN 1 END) AS my_total_npr_d
, COUNT (CASE WHEN ancestor_id != paying_account_id
AND customer_status = 'D' THEN 1 END) AS total_npr_d
FROM DUMMY2
GROUP BY ancestor_id
SELECT lpad(' ', 2*level) || ACCOUNT.ACCOUNT_ID AS LEVEL_LABEL, LEVEL, CONNECT_BY_ISCYCLE "Cycle",
ACCOUNT.PAYING_ACCOUNT_ID, ACCOUNT.PARENT_ACCOUNT_ID, ACCOUNT.ACCOUNT_ID,
DUMMY.my_total_pr_a, DUMMY.total_pr_a, DUMMY.my_total_npr_a, DUMMY.total_npr_a,
DUMMY.my_total_pr_d, DUMMY.total_pr_d, DUMMY.my_total_npr_d, DUMMY.total_npr_d
from ACCOUNT INNER JOIN DUMMY ON ACCOUNT.account_id = DUMMY.ancestor_id
START WITH ACCOUNT.parent_account_id = ACCOUNT.account_id
CONNECT BY NOCYCLE PRIOR ACCOUNT.account_id = ACCOUNT.parent_account_idDDL
CREATE TABLE ACCOUNT
"CUSTOMER_ID" NUMBER(20,0) NOT NULL ENABLE,
"PAYING_ACCOUNT_ID" NUMBER(20,0),
"PARENT_ACCOUNT_ID" NUMBER(20,0),
"ACCOUNT_ID" NUMBER,
"COMPANY_ID" NUMBER
CREATE TABLE CUSTOMER_STATUS
"CUSTOMER_ID" NUMBER(10,0),
"CUSTOMER_STATUS" VARCHAR2(1 BYTE)
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4571111,4571111,4571111);
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4571112,4571112,4571111);
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4571113,4571113,4571111);
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (3996786,3995313,3995313);
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4008375,3995313,3995313);
Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (3995313,3995313,3995313);
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (3996786,'D');
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4008375,'A');
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (3995313,'A');
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4571111,'A');
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4571112,'A');
Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4571113,'A');Hi thanks for your information and explanation..
To answer your doubt, below explain the rational
The logic for TOTAL_XXX
for instance, I've picked only below data to explain the rational
Account_id Paying_account Parent_account status
3995313 3995313 3995313 Active
3996786 3995313 3995313 Deactivated
4008375 3995313 3995313 Active
Showing accounts relations, status, PR\NPR, and hierarchy we have
Account 3995313 (PR, Active)
- Account 3996786 (NPR, Deactive)
- Account 4008375 (NPR, Active)
TOTAL_PR_ACCOUNTS_A - Sum of all accounts of the structure that are PR and in sates considered Active.
The TOP account is not included in the sum, only TOP account childs
For account 3995313 the TOTAL_PR_ACCOUNTS_A is 0 (Based on the definiton, to calculate TOTAL_PR_ACCOUNTS_A, we need go throught the entire structure for that
account. In this case, we have 3995313, 3996786 and 4008375. Now we go the this three account one by one
first is 3995313, this account is a TOP account in the entire structure, so is not included in the sum.
second is 3996786, this account is not a TOP account therefore should be included in the sum, however this account is NPR and Deactive, so is disqualify.
third is 4008375, this account is not a TOP account and is active account therefore should be included in the sum, however this account is NPR so is disqualify.)
For account 3996786 the TOTAL_PR_ACCOUNTS_A is 0 ( the definiton is exactly same as the above)
For account 4008375 the TOTAL_PR_ACCOUNTS_A is 0 ( the definiton is exactly same as the above)
For account 3995313 the TOTAL_NPR_ACCOUNTS_A is 1 (Based on the definiton, to calculate TOTAL_NPR_ACCOUNTS_A, we need go throught the entire structure for that
account. In this case, we have 3995313, 3996786 and 4008375. Now we go the this three account one by
first is 3995313, this account is a TOP account in the entire structure, so is not included in the sum.
second is 3996786, this account is not a TOP account and is NPR therefore should be included in the sum, however this account is Deactive, so is disqualify.
third is 4008375, this account is not a TOP account and is active and NPR account therefore should be included in the sum, so is disqualify.)
For account 3996786 the TOTAL_PR_ACCOUNTS_A is 1 ( the definiton is exactly same as the above)
For account 4008375 the TOTAL_PR_ACCOUNTS_A is 1 ( the definiton is exactly same as the above)After execute the code as provided, seems the result was correct but I need more times to verify as I have a milions of records in the DB.
I tried to modify the code to have better performance , but failed to process, Appreciate any help :)
WITH got_descendants AS
SELECT CONNECT_BY_ROOT a.account_id AS ancestor_id
, CONNECT_BY_ROOT a.parent_account_id AS parent_account_id -- ***** NEW *****
, a.paying_account_id
, a.account_id
, c.customer_status
, LEVEL AS lvl
, CONNECT_BY_ISCYCLE AS cycle
, CASE
WHEN CONNECT_BY_ROOT a.account_id
= CONNECT_BY_ROOT a.parent_account_id
THEN ROWNUM
END AS r_num
FROM account a inner join customer_status c
on a.account_id = c.customer_id
CONNECT BY NOCYCLE PRIOR a.account_id = a.parent_account_id
AND a.account_id != a.parent_account_id
ORDER SIBLINGS BY a.account_id -- Optional
, got_o_num AS
SELECT got_descendants.*
, MIN (r_num) OVER (PARTITION BY account_id) AS o_num
, MAX (lvl) OVER (PARTITION BY account_id) AS max_lvl
FROM got_descendants
), dummy AS
SELECT ancestor_id
, COUNT ( CASE WHEN lvl > 1
AND account_id = paying_account_id
AND ancestor_id != account_id
AND customer_status = 'Active'
THEN 1
END
) AS my_total_pr_a
, COUNT (CASE WHEN lvl > 1
AND account_id != paying_account_id
And ancestor_id != account_id
AND customer_status = 'Active' THEN 1 END) AS my_total_npr_a
, COUNT (CASE WHEN lvl > 1
AND account_id = paying_account_id
And ancestor_id != account_id
AND customer_status = 'Deactive' THEN 1 END) AS my_total_pr_d
, COUNT (CASE WHEN lvl > 1
AND account_id != paying_account_id
And ancestor_id != account_id
AND customer_status = 'Deactive' THEN 1 END) AS my_total_npr_d
FROM got_o_num
GROUP BY ancestor_id
--select o_num from dummy
SELECT LPAD ( ' '
, 2 * (MIN (max_lvl) - 1)
) || ancestor_id AS level_label
, MIN (max_lvl) AS "Level"
, MIN (cycle) AS "Cycle"
, ancestor_id AS account_id -- ***** NEW *****
, MIN (paying_account_id) AS paying_account
, MIN (parent_account_id) AS parent_account_id -- ***** NEW *****
, dummy.my_total_pr_a
, CONNECT_BY_ROOT dummy.my_total_pr_a AS total_pr_a
, dummy.my_total_npr_a
, CONNECT_BY_ROOT dummy.my_total_npr_a AS total_npr_a
, dummy.my_total_pr_d
, CONNECT_BY_ROOT dummy.my_total_pr_d AS total_pr_d
, dummy.my_total_npr_d
, CONNECT_BY_ROOT dummy.my_total_npr_d AS total_npr_d
FROM dummy
GROUP BY ancestor_id
ORDER BY MIN (o_num) -
Hide a row in the table.
Hi,
In my application, there is a table and an input form. I have bound the table and input fields in the form to the same context node. Now when I am validating the form, the input fields values are getting showed in the table.
I have to show the table row, only when all the validations are correct and the user got saved in the back end.
Is this correct design?
Since only one such column is getting showed in the row, can I go with an option to hide the row and still show the values in the input form.
Edited by: Tony on Feb 20, 2009 5:06 PMHi Tony,
I guess the way you are following will always give you wrong result. Reason being the same attribute and node binded to both input field and Table. This will behave as the way have told.. That means as soon as some value will be entered in th inpu field the table will get populated with the same attribute value.
I guess the reason is quite simple to understand. If the same attribute is binded to both UI elements (InputFiled and Table), then as soon as any of these value will be updated, same value will be shown in the other UI element.
To fix this issue you can follow this approach:
1) Create separate node or a attribute for the inputfield. And bind this attribute to the Inputfiled UI element.
2) Keep the binding of the table as it is.
3) As soon as user enter some value in the inout field and hit enter, fire a function or validation check which you were talking about. There is event for onEnter in inputfield. You can use the same.
4) If the validation succeds then save the value in the backend and create a new element of the table and copy the value of the attribute of input field to the Table attribute whichis binded to Table.
Following this way will definitely solve you issue. If you require any further help please let me know. However you can easily get the code for creation of the new element of the node which is binded to table. Even then if you require any help, please feel free to revert back.
Hope this helps you!!
Thanks and Regards
Pravesh -
Eliminate duplicate rows from the report 6i output
Hi All,
I have generated a report output with the group by and summary options.
For Ex: report has num and amount columns
I had to sum the amount group by num
NUM AMOUNT
1 100
1 50
2 10
2 100
After group by and summary functions the report is generating the output as follows...
NUM AMOUNT
1 150
1 150
2 110
2 110
I want to eliminate the duplicate rows and want the output as follows...
NUM AMOUNT
1 150
2 110
I tried all the ways to implement distinct, but not able to.
I donot want to implement distinct on the query but want to perform at the report level.
Please help me in this ASAP.
Thanks,
VijayIt would be helpful if you post your query, should by something like
SELECT NUM, SUM(AMOUNT)
FROM TABLE
GROUP BY NUM
ORDER BY 1this would not create duplicates with your given example data. -
Hi,
I am having a difficult time deleting empty rows in a table. I used HideDuplicates under properties to hide any of the duplicated data but now it is leaving me an empty row in the table. I tried to use the following codes but none of them seemed to work:
=Iif(Previous(Fields!Apps.Value) = Fields!Apps.Value, True, False)
=IIF(fields!Apps.value IS NOTHING, True, False)
=isnothing(fields!Apps.value)
=if(Fields!Apps.Value = "",
true, false).
=IIF(IsNothing(Fields!Apps.Value),True,False)
=iif(Fields!Apps.IsMissing,True,False)
Might anyone know another code I might use to delete the empty rows?
Thank you in advance!What you are looking for is probably the Visibility option not the HideDuplicates. You can right click on the row and choose
Row Visibility. Select "Show or hide based on an expression" and put in the expression that resolves to true to hide the row, and false to show it.
The HideDuplicates field that you are using is there to hide duplicating text and not entire rows. For example if you have:
Value1
5
Value1
15
Value1
20
Value2
10
You would then get:
Value1
5
15
20
Value2
10
I hope that helped.
Regards,
Andrew. -
Set maximum matrix row and column size
I hope someone can help me with this. Is there any way to set the row and column size of a matrix control? I have not been able to find a solution. The only way I've been able to set the size is by resetting matrix to its previous state if the user inputs a value outside of the bounds I would like to set. This is done in the 'value changed' event case.
The matrix is large and therefore I cannot increase the size of the control to be the maximum size and then hide the row and column index controls. These have to be displayed.
Any suggestions or help would be greatly appreciated. Thanks in advance.Here's a quick and dirty way.
Simply hide the index controls and replace them with some fake numeric controls and set the data range accoding to your requirements.
In the attached example (LV8.0), the fake index controls are limited to 0..2, the array size is 5x5 and the displayed array portion is 3x3. Seems to work fine.
(Of course you could add a bit more code to set the limits automatically based on the various sizes.)
You could also make it more fancy and turn the entire thing into an Xcontrol.
Message Edited by altenbach on 06-06-2007 05:32 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
LimitArrayControl.vi 18 KB -
How to find duplicate row in sql query?
Hi All,
Please solve my query, find duplicate row and how to count its. your suggestion would be greatly appreciated.You can use group by and having.
SQL> WITH t
2 AS (SELECT LEVEL id
3 FROM DUAL
4 CONNECT BY LEVEL <= 5
5 UNION ALL
6 SELECT LEVEL + 2
7 FROM DUAL
8 CONNECT BY LEVEL <= 3)
9 SELECT *
10 FROM t;
ID
1
2
3
4
5
3
4
5
8 rows selected.
SQL> WITH t
2 AS (SELECT LEVEL id
3 FROM DUAL
4 CONNECT BY LEVEL <= 5
5 UNION ALL
6 SELECT LEVEL + 2
7 FROM DUAL
8 CONNECT BY LEVEL <= 3)
9 SELECT id, COUNT (*)
10 FROM t
11 GROUP BY id
12 HAVING COUNT (*) > 1;
ID COUNT(*)
3 2
4 2
5 2
SQL> -
How to use analytic function with aggregate function
hello
can we use analytic function and aggrgate function in same qurey? i tried to find any example on Net but not get any example how both of these function works together. Any link or example plz share with me
Edited by: Oracle Studnet on Nov 15, 2009 10:29 PMselect
t1.region_name,
t2.division_name,
t3.month,
t3.amount mthly_sales,
max(t3.amount) over (partition by t1.region_name, t2.division_name)
max_mthly_sales
from
region t1,
division t2,
sales t3
where
t1.region_id=t3.region_id
and
t2.division_id=t3.division_id
and
t3.year=2004
Source:http://www.orafusion.com/art_anlytc.htm
Here max (aggregate) and over partition by (analytic) function is in same query. So it means we can use aggregate and analytic function in same query and more than one analytic function in same query also.
Hth
Girish Sharma -
Problem:
In a table duplicate records are there, i want to retive the rows which are duplicated. What is the query to find out the rows containing the duplicate rows and delete the duplicate one?
Thanks
swadhindelete from emp where
rowid in ( select max(rowid) from emp group by ename having count(1) > 1);This will not work if you have more than two duplicated rows per condition:
SQL> select * from t;
ID
1
1
1
1
2
2
3
3
4
9 rows selected.
SQL> delete
2 from t
3 where rowid in
4 (select max(rowid) from t group by id having count(*) > 1);
3 rows deleted.
SQL> select * from t;
ID
1
1
1
2
3
4
6 rows selected.Rgds. -
Help regarding accessing duplicate rows in a procedure
Hi All,
I have duplaicate records in my table. In my procedure, I have to access only one row and leave the remaining rows unprocessed.
For ex:-
EMPNO ENAME DEPTNO DNAME SAL
1128 SMITH 140 MARKT 200
1128 SMITH 140 MARKT 400
1128 SMITH 140 MARKT 600
1160 DARON 150 BUSSN 300
1160 DARON 150 BUSSN 500
1196 DAYLE 180 SPORT 800
In my procedure, I need to process only
1128 SMITH 140 MARKT 200
1160 DARON 150 BUSSN 300
1196 DAYLE 180 SPORT 800
only these rows and dont process the remaining rows. Instead of deleteing the duplicate rows and then accessing, how to handle this duplication in the procedure. will write a cursor and open it and process the first row. when the cursor fetches the second row, as it a duplicate interms of EMPNO, i dont want to process that and skip to 4th record. process 4th record and skip 5th as it is a duplicate and then process 6th.
Will write some validations to check whether EMPNO and DEPTNO exists in the database and and whether those two are linked to each other and then process it.
Help Appreciated how to handle it in a procedure.
ThanksHi there,
from my understanding of what you've asked, you should just need to ensure your cursor is ordered by "empno" and "sal" and then assign empno to a variable each time you fetch the cursor or loop arround depending on how you do it.
then you only process the row when the data in the cursor.empno field is different from the data in the variable.
e.g. (disclaimer: quick and dirty)
declare
v_empno number;
begin
v_empno := 0;
for v_cursor in (select * from table order by empno, sal) loop
if v_cursor.empno <> v_empno then
--process record
v_empno := v_cursor.empno;
end if;
end loop;
end;
Maybe you are looking for
-
Importing UDF data through DTW
Hi Experts, I am using SAP Business One 2007B PL00. I have created 2 UDF's on row level in marketing documents. These fields i have defined to track the legacy PO/SO number and the other UDF to track the date in yyyymm format which is present in lega
-
I have a Ipod Touch 2G that is stuck on the "Connect to Itunes Logo" How can I get it back in operating order with out the access to a home computer? Can anybody Help me? I need it back to work.....
-
A more successful experiment in creating compositable user interfaces for Config Dialogs
A couple weeks ago I posted an experiment in creating compositable user interfaces using transparent subpanels. The approach might best be described as, "It at least was notable for being novel." Today, I'm posting another attempt, this one along mor
-
Error during creation of SC by described requirement
Dear Expert, When I try to create SC through described requirement, I am getting error as "Enter the Company Code". We are using SRM7.0 Extended Classic Scenario. The employee has the attribute of Company code is maintained in PPOMA_BBP. Also we dont
-
Flash player doesn't work on some websites
Hi, For some reason, video stays black on some websites, some other websites like youtube work. I applied the permissions fix that I found which worked at first but now the problem is back and this fix doesn't work anymore. I tried everything from fr