Re: Help on (sub)-select

From: Philip Warner <pjw(at)rhyme(dot)com(dot)au>
To: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Help on (sub)-select
Date: 2002-12-20 10:51:19
Message-ID: 5.1.0.14.0.20021220214822.02d7e360@mail.rhyme.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 10:21 AM 20/12/2002 +0000, Gary Stainburn wrote:
>nymr=# select r.*, s.tally from roster r,
>nymr-# (select count(*) as tally from roster_staff where
>nymr(# rsdate = '2002-01-01' and rsgid = 11 and rsgsid = 2) as s
>nymr-# where rodate = '2002-01-01' and rogid = 11 and rogsid = 2;
> rodate | rogid | rogsid | rorequired | rooptional | tally
>------------+-------+--------+------------+------------+-------
> 2002-01-01 | 11 | 2 | 0 | 1 | 2
>(1 row)

Try something like:

select r.*, count(*) from roster r, roster_staff s
where rsdate = rodate and rsgid = rogid and rsgsid = rogid
group by r.*

or

select r.*, (select count(*) from roster_staff s
where rsdate = rodate and rsgid = rogid and rsgsid = rogid
) roster r

May not be exactly right, but you should get the idea

----------------------------------------------------------------
Philip Warner | __---_____
Albatross Consulting Pty. Ltd. |----/ - \
(A.B.N. 75 008 659 498) | /(@) ______---_
Tel: (+61) 0500 83 82 81 | _________ \
Fax: (+61) 03 5330 3172 | ___________ |
Http://www.rhyme.com.au | / \|
| --________--
PGP key available upon request, | /
and from pgp5.ai.mit.edu:11371 |/

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2002-12-20 11:48:24 Re: Help on (sub)-select
Previous Message Christoph Haller 2002-12-20 10:22:37 Re: UPDATE with a SELECT and subSELECT(About comparing dates and non dates data)