From: Srikanth Rao <srirao_us@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Counting rows in a table
Date: Mon, 14 May 2001 08:21:58 -0700 (PDT)
Message-ID: <20010514152158.12927.qmail@web6302.mail.yahoo.com> (raw)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
I have a query as follows:
SELECT date(c.timestart) as ondate,
c.userid,
u.username,
count(c.callinfoid) as numCalls,
sum(b.broquant) as numBroc,
sum(b.broquant)/count(c.callinfoid) as
BrochuresaCall
FROM callinfo c, user_ u, brochurerequest b
WHERE c.userid = u.userid
AND
b.callinfoid = c.callinfoid
GROUP BY c.userid,u.username,ondate;
But, I want numCalls to count rows where b.callinfoid
is not in c.callinfoid.
How do i do it ? I am on version 7.0.2.
Below are the table create statements that I have.
-------------------------------------------------------------------------
CREATE TABLE Patient
(
patientId INT8,
personId INT8 ,
constraint Patient_key primary key (patientId)
);
CREATE TABLE User_
(
userId INT8,
userName TEXT constraint uname_uniq unique,
userPassword TEXT,
userRole INTEGER,
userMode TEXT,
personId INT8,
constraint User_key primary key (userId)
);
CREATE TABLE CallInfo
(
callInfoId INT8,
timeStart TIMESTAMP,
timeStop TIMESTAMP,
marketing TEXT,
userId INT8 constraint CI_U_FK references User_,
patientId INT8,
constraint CallInfo_key primary key (callinfoId)
);
CREATE TABLE BrochureRequest
(
broQuant INTEGER,
method TEXT,
comment TEXT,
officeId INT8,
callInfoId INT8 constraint BR_CI_FK references
CallInfo
);
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: srirao_us@yahoo.com
Subject: Re: Counting rows in a table
In-Reply-To: <20010514152158.12927.qmail@web6302.mail.yahoo.com>
References: <20010514152158.12927.qmail@web6302.mail.yahoo.com>
* 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