From: | Srikanth Rao <srirao_us(at)yahoo(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Counting rows in a table |
Date: | 2001-05-14 15:21:58 |
Message-ID: | 20010514152158.12927.qmail@web6302.mail.yahoo.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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/
From | Date | Subject | |
---|---|---|---|
Next Message | Larry Rosenman | 2001-05-14 18:00:25 | plpgsql function / ??? / help |
Previous Message | Martín Marqués | 2001-05-14 15:21:56 | Re: fatal ERROR running simple join query... |