Skip site navigation (1) Skip section navigation (2)

Help on (sub)-select

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: pgsql-sql(at)postgresql(dot)org
Subject: Help on (sub)-select
Date: 2002-12-20 10:21:50
Message-ID: 200212201021.50475.gary.stainburn@ringways.co.uk (view raw or flat)
Thread:
Lists: pgsql-sql
Hi Folks,

I have two tables 

roster holds the duties to be performed and the number of people required per 
duty.
roster_staff holds the people allocated to perform that duty.

I'm trying to create a select that will tally the roster_staff and include it 
with the roster details.  I've managed to get it working for a specific day, 
but I can't seem to manage to get it working generically.

here's the select I've got that works, along with the output:

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)

nymr=#

What I want to be able to do is select multiple rows and have the correct 
tally appear for that row.
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     


Responses

pgsql-sql by date

Next:From: Christoph HallerDate: 2002-12-20 10:22:37
Subject: Re: UPDATE with a SELECT and subSELECT(About comparing dates and non dates data)
Previous:From: javier garciaDate: 2002-12-19 16:16:45
Subject: Re: UPDATE with a SELECT and subSELECT(About comparing dates and non dates data)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group