Re: [SQL] Ask a PostgreSql question (about select )

2006-03-12 Thread Michael Glaesemann
Please post questions to the list. I'm forwarding this to the SQL list, as I think it's probably most applicable. I don't know much about the Oracle syntax you've used. Hopefully someone will be able to help you. On Mar 13, 2006, at 12:30 , min wrote: Please help me one PostgreSQL Statem

Re: [SQL] pgsql aggregate: conditional max

2006-03-12 Thread Weimao Ke
Daniel CAUNE wrote: SELECT aid, cat FROM table, ( SELECT aid, max(weight) as weight FROM table GROUP BY aid) AS tablemaxweight WHERE table.aid = tablemaxweight.aid AND table.weight = tablemaxweight.aid; There is a limit case you don't specify how to deal with, when two or mor

Re: [SQL] Question re: relational technique

2006-03-12 Thread Robert Paulsen
On Sunday 12 March 2006 11:29, chester c young wrote: > --- Robert Paulsen <[EMAIL PROTECTED]> wrote: > > One problem with the above is that the list of attributes is fixed. I > > am looking for a way to assign new, previously undefined, attributes > > to > > > items without changing the table stru

Re: [SQL] Question re: relational technique

2006-03-12 Thread chester c young
--- Robert Paulsen <[EMAIL PROTECTED]> wrote: > One problem with the above is that the list of attributes is fixed. I > am looking for a way to assign new, previously undefined, attributes to > items without changing the table structure. Is it ever appropriate to do > the following? > ... There a

Re: [SQL] pgsql aggregate: conditional max

2006-03-12 Thread Weimao Ke
Michael Fuhr wrote: SELECT DISTINCT ON (aid) aid, cat FROM tablename ORDER BY aid, weight DESC, cat; Good pointer. I think this will solve my problem. :) SELECT aid, cat FROM tablename AS t JOIN (SELECT aid, max(weight) AS weight FROM tablename GROUP BY aid) AS s USING (aid, weig

[SQL] Question re: relational technique

2006-03-12 Thread Robert Paulsen
Here is a sample table: item item_id int namechar attrib1 char attrib2 char attrib3 char One problem with the above is that the list of attributes is fixed. I am looking for a way to assign new, previously undefined, attributes to items without changing the table structure

Re: [SQL] pgsql aggregate: conditional max

2006-03-12 Thread Weimao Ke
Michael Fuhr wrote: On Sun, Mar 12, 2006 at 12:34:57AM -0500, Jeffrey Melloy wrote: Should be able to do this with a standard max() aggregate. select aid, cat, max(weight) from table group by aid, cat; That query returns the maximum weight for each (aid, cat) pair. Against the exampl

Re: [SQL] pgsql aggregate: conditional max

2006-03-12 Thread Daniel CAUNE
> Hi, > > I need a special aggregation function. For instance, given the following > table data: > >aid| cat | weight > --+-+- > a1 | Drama | 1 > a1 | Romance | 6 > a1 | Short | 1 > a1 | Other | 7 > a2 | Comedy | 1