Pradeep Kumar, August 09, 2016 - 2:55 pm UTC
Thanks for the response.
CASE statement always returns one row.
Just to simplify the query I'm rephrasing it below :
SELECT row_number() OVER( order by leafv , value_group , l1d ,l2d ,l3d ,l4d ,l5d ,l6d ,l7d ) MYROWNUM ,
S.*
FROM
(SELECT NVL(SKU, 'NULLVALUE') leafv,
NVL(chain_name,'NULLVALUE') value_group,
NVL(level_10_description ,'NULLVALUE') l10d,
NVL(level_1_description,'NULLVALUE') l1d,
NVL(level_2_description,'NULLVALUE') l2d,
NVL(level_3_description,'NULLVALUE') l3d,
NVL(level_4_description,'NULLVALUE') l4d,
NVL(level_5_description,'NULLVALUE') l5d,
NVL(level_6_description,'NULLVALUE') l6d,
NVL(level_7_description,'NULLVALUE') l7d,
NVL(level_8_description,'NULLVALUE') l8d,
NVL(level_9_description,'NULLVALUE') l9d
FROM t_product_catalog_flat
ORDER BY leafv ,
value_group ,
l1d ,
l2d ,
l3d ,
l4d ,
l5d ,
l6d ,
l7d ,
l8d ,
l9d ,
l10d
) S
WHERE MYROWNUM=1
There are duplicates for the combination of columns (leafv , value_group , l1d ,l2d ,l3d ,l4d ,l5d ,l6d ,l7d )
I want just one row for each of these grouped value.
Above query is throwing error :ORA-00904: "MYROWNUM": invalid identifier.
When I remove WHERE MYROWNUM=1 , query returns the result but computes MYROWNUM with distinct values even if there are duplicates for above set of columns
August 09, 2016 - 3:38 pm UTC
You need another outer query around this one that restricts to just first rows!
Pradeep Kumar, August 09, 2016 - 5:45 pm UTC
No, It didn't get the desired result.
This is what the tables and test data we have. Out of 19 rows, 3 are duplicates ( combination of values in all the columns) .
I'm expecting 16 rows as the result of query, please let me know
CREATE TABLE test_partition
(
SKU VARCHAR2(50),
chain_name VARCHAR2(50),
level_1_description VARCHAR2(50),
level_2_description VARCHAR2(50),
level_3_description VARCHAR2(50),
level_4_description VARCHAR2(50),
level_5_description VARCHAR2(50),
level_6_description VARCHAR2(50),
level_7_description VARCHAR2(50),
level_8_description VARCHAR2(50),
level_9_description VARCHAR2(50),
level_10_description VARCHAR2(50)
);
insert into test_partition values ('001456','AUTO_CHAIN','TEXAS','IRVING','Test Store Alpha',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('123','TEST','test','wef','wefg',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('124','TEST','test','wef','wef',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('23234','AUTO_CHAIN','TEXAS','IRVING','Test Store Alpha',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('5R65','AUTO_CHAIN','GEF','NEW',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('GH','AUTO_CHAIN','TEXAS','IRVING','Test Store Alpha',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('MN','AUTO_CHAIN','TEXAS','IRVING','Test Store Alpha',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('MNS','test','wef','wefg',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('SAS','AUTO_CHAIN','TEXAS','IRVING','Test Store Alpha',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('SH','AUTO_CHAIN','TEXAS','IRVING','Test Store Alpha',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('TEST','AUTO_CHAIN','TEXAS','IRVING','Test Store Alpha',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values ('mnz','AUTO_CHAIN','TEXAS','IRVING','Test Store Alpha',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values (NULL,'ERE','GEF','NEW','Test','test','test','test','test','test','test','LEVEL10');
insert into test_partition values (NULL,'AUTO_CHAIN','level1 testing','level2 testing','level3 testing','level4 testing','level5 testing','level6 testing','level7 testing','level8 testing','level9 testing','level10 testing');
insert into test_partition values (NULL,'AUTO_CHAIN','level1 testing','level2 testing','level3 testing','level4 testing','level5 testing','level6 testing','level7 testing','level8 testing','level9 testing','level10 testing');
insert into test_partition values (NULL,'POINTGIFTHAIN','gold','silver','bronze','testsampletest',NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values (NULL,'POINTGIFTHAIN','gold','silver','bronze','testsampletest',NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values (NULL,'POINTGIFTHAIN','gold class','silver class','bronze','point',NULL,NULL,NULL,NULL,NULL,NULL);
insert into test_partition values (NULL,'POINTGIFTHAIN','gold class','silver class','bronze','point',NULL,NULL,NULL,NULL,NULL,NULL);
August 10, 2016 - 9:42 am UTC
I believe the query in the reply below has the answer you're looking for.
For Pradeep
Muhammad Riaz, August 10, 2016 - 8:23 am UTC
Are you looking for something like below?
SELECT * FROM
(SELECT row_number() OVER(partition by leafv , value_group , l1d ,l2d ,l3d ,l4d ,l5d ,l6d ,l7d order by leafv , value_group , l1d ,l2d ,l3d ,l4d ,l5d ,l6d ,l7d ) MYROWNUM ,
S.*
FROM
(SELECT NVL(SKU, 'NULLVALUE') leafv,
NVL(chain_name,'NULLVALUE') value_group,
NVL(level_10_description ,'NULLVALUE') l10d,
NVL(level_1_description,'NULLVALUE') l1d,
NVL(level_2_description,'NULLVALUE') l2d,
NVL(level_3_description,'NULLVALUE') l3d,
NVL(level_4_description,'NULLVALUE') l4d,
NVL(level_5_description,'NULLVALUE') l5d,
NVL(level_6_description,'NULLVALUE') l6d,
NVL(level_7_description,'NULLVALUE') l7d,
NVL(level_8_description,'NULLVALUE') l8d,
NVL(level_9_description,'NULLVALUE') l9d
FROM test_partition
ORDER BY leafv ,
value_group ,
l1d ,
l2d ,
l3d ,
l4d ,
l5d ,
l6d ,
l7d ,
l8d ,
l9d ,
l10d
) S
)
WHERE MYROWNUM=1
August 10, 2016 - 9:43 am UTC
It gives me 16 rows on the dataset above, so I'm guessing yes!