473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 5859
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.