pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philip Warner <pjw@rhyme.com.au>
To: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: pgsql-sql@postgresql.org
Subject: Re: Help on (sub)-select
Date: Fri, 20 Dec 2002 21:51:19 +1100
Message-ID: <5.1.0.14.0.20021220214822.02d7e360@mail.rhyme.com.au> (raw)
In-Reply-To: <200212201021.50475.gary.stainburn@ringways.co.uk>

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   |/




view thread (4+ messages)  latest in thread

Message-ID: <5.1.0.14.0.20021220214822.02d7e360@mail.rhyme.com.au>
Permalink:  ../5.1.0.14.0.20021220214822.02d7e360@mail.rhyme.com.au/
Also on:    postgresql.org/message-id/5.1.0.14.0.20021220214822.02d7e360@mail.rhyme.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pjw@rhyme.com.au, gary.stainburn@ringways.co.uk
  Subject: Re: Help on (sub)-select
  In-Reply-To: <5.1.0.14.0.20021220214822.02d7e360@mail.rhyme.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox