If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > How do you group rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-11, 05:36
Barry1337 Barry1337 is offline
Registered User
 
Join Date: Oct 2011
Posts: 3
How do you group rows

Hello,

I have the following database:

1 | 'a'
1 | 'b'
1 | 'c'

And I want the following (for the sake of frequent itemset mining) :

1 | 'a','b','c'

Is there an operator in SQL to perform this action? I know you can only use aggregate functions, but I don't understand why.
Reply With Quote
  #2 (permalink)  
Old 10-13-11, 07:35
shureg shureg is offline
Registered User
 
Join Date: Oct 2011
Location: Hamburg, Germany
Posts: 15
in oracle you can use listagg function
Code:
SELECT id, LISTAGG(name, ',') WITHIN GROUP (ORDER BY name) AS n
FROM   tab
GROUP BY id;
in mysql GROUP_CONCAT function?
Reply With Quote
  #3 (permalink)  
Old 10-13-11, 07:38
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by shureg View Post
in mysql GROUP_CONCAT function?
yes

but i don't think there is anything in ANSI SQL (this forum)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 10-14-11, 07:09
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
In ANSI/ISO SQL, you'd have to use a recursive query that does the string concatenation. Also, I'm not sure if XMLAGG() is a standardized function. If so, it would be another option. by constructing an XML document, doing the aggregation there and then just getting the text data.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 02-06-12, 05:10
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,191
ANSI SQL:2003 includes "Part 14: SQL/XML".

See general descriptions in
Overview of SQL:2003
page 65-67: Part 14: SQL/XML
page 93-95: XMLAGG

SQL:2003 Has Been Published
Reply With Quote
  #6 (permalink)  
Old 02-06-12, 11:10
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Tonkuma, do you know if LISTAGG is in SQL2003 or SQL2007?
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old 02-06-12, 12:06
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,191
I searched word "LISTAGG" in draft PDFs of SQL2003 and not found the word.

I have no material of SQL2007, now.
Reply With Quote
  #8 (permalink)  
Old 02-07-12, 02:43
JarlH JarlH is offline
Registered User
 
Join Date: Dec 2008
Location: At work...
Posts: 68
And no LISTAGG found neither in SQL-2011 nor SQL-2015 draft.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On