472,358 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

SQL to aggregate values into LIST

I have a table with 2 primary keys, one is a foreign key, the other is
produced by a sequence.

I want to SELECT query for one record that has a list of the
sequence-produced values for all records with a given foreign-key
value, essentially:

Create table table1 {
fk_id number,
seq_id number
}

SELECT fk_id, LIST(seq_id)
FROM table1
WHERE fk_id = 1
GROUP BY fk_id

Is there a way to do this?
Jul 19 '05 #1
3 5780
Ariel Jakobovits wrote:
I have a table with 2 primary keys, one is a foreign key, the other is
produced by a sequence.

I want to SELECT query for one record that has a list of the
sequence-produced values for all records with a given foreign-key
value, essentially:

Create table table1 {
fk_id number,
seq_id number
}

SELECT fk_id, LIST(seq_id)
FROM table1
WHERE fk_id = 1
GROUP BY fk_id

Is there a way to do this?


SELECT seq_id
FROM table1
WHERE fk_id = 1

Or:
SELECT fk_id, seq_id
FROM table1
GROUP BY fk_id

BTW - your table has (and can have!) only one
primary key.
--

Regards,
Frank van Bortel

Jul 19 '05 #2
Not exactly.
SELECT seq_id
FROM table1
WHERE fk_id = 1
RETURNS THIS:

seq_ID
------------------
1
2
3
4

Those are four separate records. I want one record, like this:

seq_id
------------------
1,2,3,4

AND THIS:
SELECT fk_id, seq_id
FROM table1
GROUP BY fk_id


RETURNS THIS:

ERROR at line 1:
ORA-00979: not a GROUP BY expression

Any more help?
Jul 19 '05 #3
Jan
See

"User-Defined Aggregate Functions"

in "Oracle9i Data Cartridge Developer's Guide"

http://download-west.oracle.com/docs...5/dci11agg.htm
You should create a type, e.g.:

CREATE TYPE my_agg
AS OBJECT (
string_value VARCHAR2(4000)
)

with all the 4 member functions as mentioned in docs.

You will just make some modifications, e.g. in following member function,
you would write:

---------------------
MEMBER FUNCTION ODCIAggregateIterate(
self IN OUT my_agg,
p_value IN VARCHAR2)
RETURN NUMBER IS

BEGIN
self.string_value:=
self.string_value||','||p_value;
RETURN ODCIConst.Success;

END ODCIAggregateIterate;
--------------------------
After modifications in memeber functions, create a function:

---------
CREATE OR REPLACE FUNCTION my_agg_char(p_char_value IN VARCHAR2)
RETURN VARCHAR2
PARALLEL_ENABLE AGGREGATE USING my_agg;
---------

And then, just use it:
SELECT my_agg_char(col1)
FROM my_table
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bevan Ward | last post by:
Hi All I need to aggregate a query to produce the following: Workplace Avg M100 4.7 M120 3.45 Which would be a normal aggregate: SELECT Workplace, Avg(VALUE)
6
by: Steven An | last post by:
Howdy, I need to write an update query with multiple aggregate functions. Here is an example: UPDATE t SET t.a = ( select avg(f.q) from dbo.foo f where f.p = t.y ), t.b = ( select sum(f.q)...
2
by: Greg Stark | last post by:
I find I often want to be able to do joins against views where the view are aggregates on a column that has an index. Ie, something like SELECT a.*, v.n FROM a JOIN (select a_id,count(*) as n...
3
by: MrNobody | last post by:
I've read that the expression property for DataColumns is used to "Sets or retrieves the expresssion used to filter rows, calculate the values in a column, or create an aggregate column.". I...
1
by: Pascal Polleunus | last post by:
Hi, Is there an *easy* way to display a list of tables with their number of input values in psql ? Wouldn't it be useful to have the ability to execute aggregate functions with the \d command...
1
by: Scott Gerhardt | last post by:
Hello, I am new to the list, my apology if this question is beyond the scope or charter of this list. My questions is: What is the best method to perform an aggregate query to calculate sum()...
3
by: S P Arif Sahari Wibowo | last post by:
Hi! I would like to make an editable continous form, where most fields will be from table A and editable, except 1-3 fields are a glimpse into table B and uneditable. Table A relate to table B...
4
by: wrldruler | last post by:
Hello, First, I know it's against "Access Law" to save calculations in a table, but....I want/need to. I currently have sub-totals being calculated inside a form, using DMax, DCount, and...
3
by: Ariel Jakobovits | last post by:
I have a table with 2 primary keys, one is a foreign key, the other is produced by a sequence. I want to SELECT query for one record that has a list of the sequence-produced values for all...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.