Need to show other columns for SUM

From: Chuck Roberts <croberts(at)gilsongraphics(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Need to show other columns for SUM
Date: 2015-01-28 13:48:53
Message-ID: 011ac9510bd1b5258562f2584d9484eb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Postgresql 8.4.

Thank you for the help. This did what I wanted:

SELECT j.armasterid, substring(j.ccdescription from 1 for 15) as desc,
j.ccpromisedate as promdate, j.ccmasterid as jobid, sum(jc.jcactcost) as
sumactcost

FROM job j

JOIN jobcost jc ON (j.ccmasterid = jc.ccmasterid)

WHERE (j.ccpromisedate BETWEEN '2014-07-01' AND '2014-07-05') AND
(jc.jcactcost > 0)

GROUP BY j.ccmasterid, j.armasterid, j.ccdescription, j.ccpromisedate

ORDER BY j.ccmasterid ;

I just have to add the other columns I want to show in the GROUP BY clause.

Everyone has different ways of learning, and I didn't find what I needed
via Google. In case you were wondering, I learn better by example, and this
example will help me a lot in other things I have to do. Thanks!

Browse pgsql-novice by date

  From Date Subject
Next Message Benoit Izac 2015-01-28 18:31:04 Re: Need to show other columns for job table along with summing job cost
Previous Message Tom Lane 2015-01-27 21:48:16 Re: Need to show other columns for job table along with summing job cost