RE: [SQL] Odd "problem", not sure if there is a solution ....

From: "Jackson, DeJuan" <djackson(at)cpsgroup(dot)com>
To: chairudin(at)prima(dot)net(dot)id, secret <secret(at)kearneydev(dot)com>
Cc: The Hermit Hacker <scrappy(at)hub(dot)org>, pgsql-sql(at)postgreSQL(dot)org
Subject: RE: [SQL] Odd "problem", not sure if there is a solution ....
Date: 1999-03-31 16:54:01
Message-ID: D05EF808F2DFD211AE4A00105AA1B5D2037E21@cpsmail
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Look at dynamic length arrays.
-DEJ

> -----Original Message-----
> From: Chairudin Sentosa [mailto:chairudin(at)prima(dot)net(dot)id]
> Sent: Wednesday, March 31, 1999 7:12 AM
> To: secret
> Cc: The Hermit Hacker; pgsql-sql(at)postgreSQL(dot)org
> Subject: Re: [SQL] Odd "problem", not sure if there is a solution ....
>
>
> secret wrote:
>
> > The Hermit Hacker wrote:
> >
> > > am working up a database for client that contains answers
> for online
> > > testing...right now, the 'tables' look like:
> > >
> > > userid Q1 Q2 Q3 Q4 Q5 Q6 Q7 etc
> > >
> > > I want to change it so that its more generic, as:
> > >
> > > userid question_no answer
> > >
> > > so that instead of one row per user, there are X rows...
> > >
> > > the problem is that, somehow, I want the client to be
> able to view the
> > > results as the first format (ie. one line per user) with
> it being stored
> > > as multiple lines per user...
> > >
> > > Possible?
> > >
> > > Marc G. Fournier ICQ#7615664
> IRC Nick: Scrappy
> > > Systems Administrator @ hub.org
> > > primary: scrappy(at)hub(dot)org secondary:
> scrappy(at){freebsd|postgresql}.org
> >
> > Sure it's possible, if you can live with the constrant
> that every person must
> > answer every question... (Else that person will kind of
> 'disappear' <cough>):
> >
> > CREATE TABLE q (
> > person int4, -- Person ID#
> > q int4, -- Question #
> > a int4 ) -- Answer
> >
> > ftc=> select * from q where q in (1,2);
> > person|q| a
> > ------+-+--
> > 1|1| 1
> > 1|2| 1
> > 2|1|21
> > 2|2|22
> > (4 rows)
> > SELECT q1.person,
> > q1.a,
> > q2.a
> >
> > FROM q as q1,
> > q as q2
> >
> > WHERE
> > q1.person=q2.person
> > AND q1.q = 1
> > AND q2.q = 2
> > ;
> > person| a| a
> > ------+--+--
> > 1| 1| 1
> > 2|21|22
> > (2 rows)
> >
> > Your probably want to rename "a" to a1 and a2, but you
> can expand this to N
> > questions... The performance will suck if your table is
> pretty big, so I'd arrange
> > to move things to a history file every so often... Keep in
> mind people will
> > disappear if they are missing the answer to any question.
>
> Hi David,
>
> I like your solution.
> However, is there a better way to remove the constraint?
>
> Thanks
>
> Regards,
> Chai
>
>

Browse pgsql-sql by date

  From Date Subject
Next Message MESZAROS Attila 1999-03-31 19:35:18 select ... from (select .. from where.. ) where ... ?
Previous Message Oliver Smith 1999-03-31 16:16:11 Re: [SQL] merging date and time