Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id BA1AF632E36 for ; Thu, 23 Jul 2009 06:59:25 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 65532-01 for ; Thu, 23 Jul 2009 06:59:09 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by mail.postgresql.org (Postfix) with ESMTP id 5CD356332AB for ; Thu, 23 Jul 2009 06:59:07 -0300 (ADT) Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1MTv4r-0002pT-Pp for pgsql-sql@postgresql.org; Thu, 23 Jul 2009 02:59:05 -0700 Message-ID: <24622738.post@talk.nabble.com> Date: Thu, 23 Jul 2009 02:59:05 -0700 (PDT) From: bartjoosen To: pgsql-sql@postgresql.org Subject: using count in other column MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: bartjoosen@hotmail.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.209 tagged_above=-10 required=5 tests=AWL=2.092, FORGED_HOTMAIL_RCVD2=1.117 X-Spam-Level: *** X-Archive-Number: 200907/120 X-Sequence-Number: 32861 Hi, I made up a query to make a count for each item for each month/year: SELECT"Artnr_ID", to_char("Date_plan","YYYY") AS "Jaar", to_char("Date_plan","MM") AS "Maand", Count("tblArtnrs"."Artikelnr") AS "Monthly_count", "val1","val2","val3" FROM (("tblAnalyses" INNER JOIN "tblStudies" ON "tblAnalyses"."Studie_ID" = "tblStudies"."Studie_ID") INNER JOIN "tblFichenr" ON "tblStudies"."ID_fichenr" = "tblFichenr"."ID") INNER JOIN "tblArtnrs" ON "tblFichenr"."ID_Art_nrs" = "tblArtnrs"."Artnr_ID" GROUP BY "tblArtnrs"."Artnr_ID", to_char("Date_plan","YYYY") , to_char("Date_plan","MM"), "val1","val2","val3"; Now I want to use the "Monthly_count" value for further calculations with other columns. I tried to use "Monthly_count"+ "val1" + "Monthly_count" * "val2" + "Monthly_count" *"val3" But "Monthly_count" is not recognised in my calculations. How can this be solved? Thanks Bart -- View this message in context: http://www.nabble.com/using-count-in-other-column-tp24622738p24622738.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.