dbTalk Databases Forums  

get distinct values

comp.databases.oracle.server comp.databases.oracle.server


Discuss get distinct values in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
webtourist
 
Posts: n/a

Default get distinct values - 03-12-2010 , 04:58 PM






Quote:
SELECT deptno,
2 substr(REPLACE(REPLACE(xmlagg(xmlelement("x", job) ORDER BY
job), '</x>'), '<x>', ' '), 2) job_list
3 FROM emp
4 GROUP BY deptno
5 ORDER BY deptno
6/

DEPTNO JOB_LIST
------ ----------------------------------------------------
10 CLERK MANAGER PRESIDENT
20 ANALYST ANALYST CLERK CLERK MANAGER
30 CLERK MANAGER SALESMAN SALESMAN SALESMAN SALESMAN



How can I get result like this: (distinct names in "job_list") ?


DEPTNO JOB_LIST
------ ----------------------------------------------------
10 CLERK MANAGER PRESIDENT
20 ANALYST CLERK MANAGER
30 CLERK MANAGER SALESMAN

Reply With Quote
  #2  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: get distinct values - 03-12-2010 , 05:08 PM






On 12.03.2010 22:58, webtourist wrote:
Quote:
SELECT deptno,
2 substr(REPLACE(REPLACE(xmlagg(xmlelement("x", job) ORDER BY
job), '</x>'),'<x>', ' '), 2) job_list
3 FROM emp
4 GROUP BY deptno
5 ORDER BY deptno
6/

DEPTNO JOB_LIST
------ ----------------------------------------------------
10 CLERK MANAGER PRESIDENT
20 ANALYST ANALYST CLERK CLERK MANAGER
30 CLERK MANAGER SALESMAN SALESMAN SALESMAN SALESMAN



How can I get result like this: (distinct names in "job_list") ?


DEPTNO JOB_LIST
------ ----------------------------------------------------
10 CLERK MANAGER PRESIDENT
20 ANALYST CLERK MANAGER
30 CLERK MANAGER SALESMAN
Silly approach:

select deptno,
substr(replace(replace(xmlagg(xmlelement("x", job) order by job),
'</x>'), '<x>', ' '), 2) job_list
from (select unique deptno,job from emp) emp
group by deptno
order by deptno

?

Best regards

Maxim

Reply With Quote
  #3  
Old   
John Hurley
 
Posts: n/a

Default Re: get distinct values - 03-12-2010 , 06:42 PM



On Mar 12, 4:58*pm, webtourist <webtour... (AT) gmail (DOT) com> wrote:

snip

Quote:
How can I get result like this: (distinct names in "job_list") ?

DEPTNO JOB_LIST
------ ----------------------------------------------------
* * 10 CLERK MANAGER PRESIDENT
* * 20 ANALYST CLERK MANAGER
* * 30 CLERK MANAGER SALESMAN
Are you running 7.3.4?

Reply With Quote
  #4  
Old   
Shakespeare
 
Posts: n/a

Default Re: get distinct values - 03-14-2010 , 04:50 AM



Op 13-3-2010 0:42, John Hurley schreef:
Quote:
On Mar 12, 4:58 pm, webtourist<webtour... (AT) gmail (DOT) com> wrote:

snip

How can I get result like this: (distinct names in "job_list") ?

DEPTNO JOB_LIST
------ ----------------------------------------------------
10 CLERK MANAGER PRESIDENT
20 ANALYST CLERK MANAGER
30 CLERK MANAGER SALESMAN

Are you running 7.3.4?
Was xmlagg in that version?

Shakespeare

Reply With Quote
  #5  
Old   
webtourist
 
Posts: n/a

Default Re: get distinct values - 03-15-2010 , 01:21 PM



On Mar 12, 7:42*pm, John Hurley <johnbhur... (AT) sbcglobal (DOT) net> wrote:
Quote:
Are you running 7.3.4?

no, it's too advanced for us....we're on 10gR2

Reply With Quote
  #6  
Old   
webtourist
 
Posts: n/a

Default Re: get distinct values - 03-25-2010 , 02:58 PM



solution found:

SELECT deptno,
substr(REPLACE(REPLACE(xmlagg(xmlelement("x", job) ORDER BY
job), '</x>'), '<x>', ' '), 2) job_list,
wmsys.wm_concat(DISTINCT job) job_list_distinct
FROM emp
GROUP BY deptno
ORDER BY deptno



I win

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.