sum(field) as total group with a where condition...

From: "Dave VanAuken" <dave(at)hawk-systems(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: sum(field) as total group with a where condition...
Date: 2001-09-09 18:12:39
Message-ID: DBEIKNMKGOBGNDHAAKGNCEDGIGAA.dave@hawk-systems.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Am trying to accomplish a search within pgsql (from PHP though not a PHP issue
other than I need one command line)

SELECT field1,field2,sum(field3) AS total FROM table WHERE field2=12345 GROUP BY
field1

field1 field2 field3
------ ------ ------
55555 12344 10
55555 12345 10
55555 12345 10
44444 12345 10
33333 12345 10
66666 12346 10
77777 12346 10
88888 12347 10

and want it to find all those that match a particular date (field2), then return
sums for each field1... using the above table should generate the following
result for field2=12345

55555 12345 20
44444 12345 10
33333 12345 10

It is hacking on the query, and again, I am calling this from a PHP script so it
would be easiers if it can be accomplished in one select query for the return
result.

Appreciate any insight.

Dave

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2001-09-09 19:06:15 Re: sum(field) as total group with a where condition...
Previous Message Vince Vielhaber 2001-09-09 13:40:42 Re: Idea: jobs.postgresql.org