I have a table with the follwing data
Case 1:
table1
-------------
id type
-------------
1 X
1 Y
2 X
3 Z
3 X
-------------
Now as you see X is common to all the id ,so i need to return X in this case
Case2 :
table1
-------------
id type
-------------
1 X
1 Y
2 X
2 Y
3 X
3 Y
--------------
In this case both X and Y are common,then i need to return both Xand Y comma seperated (X,y)
Case 3
table1
-------------
id type
-------------
1 X
1 Y
2 X
2 Y
3 X
3 Y
4 NULL
------------------
If a null came to any of the record , i need to return NULL
Actually ,the data i have shouwn you , is been populated from 3 tables , so i have already written the query for that ,but now i need to compare the groups for the common data within groups ,that is confusing me ,how to compare the groups ?
Note :Here group is based on ID
Any help would be appriciated
you could count the occurances compared to the count of the IDs?
in 11g you have
LISTAGGinstead ofWM_CONCATof course. if for each id, the sametypeoccurs many times, you can changecount(*) over (partition by type)tocount(distinct id) over (partition by type)edit:
If you had
(rather than 4, NULL) and also want to return a NULL rather than a delimited list in that case then you could add a check (with the 4, NULL above it would return a null even on the prior SQL version as the counts would’nt tie up):