Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 31E8FB5DBE5 for ; Fri, 12 Aug 2011 13:04:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 63419-10 for ; Fri, 12 Aug 2011 16:03:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from hermes.marktest.pt (iota.marktest.pt [80.251.174.118]) by mail.postgresql.org (Postfix) with ESMTP id 0A402B5DBCE for ; Fri, 12 Aug 2011 13:03:55 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by hermes.marktest.pt (Postfix) with ESMTP id 2D7B61A8217; Fri, 12 Aug 2011 17:03:54 +0100 (WEST) X-Virus-Scanned: amavisd-new at marktest.pt Received: from hermes.marktest.pt ([127.0.0.1]) by localhost (hermes.marktest.pt [127.0.0.1]) (amavisd-new, port 11124) with ESMTP id dzeehMFyf67U; Fri, 12 Aug 2011 17:03:54 +0100 (WEST) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by hermes.marktest.pt (Postfix) with ESMTP id 030551A8215; Fri, 12 Aug 2011 17:03:54 +0100 (WEST) Message-ID: <96225C62740C45BB83267537E29E8712@marktestcr.marktest.pt> From: "Oliveiros d'Azevedo Cristina" To: "tlund79" , References: <1313147137184-4692865.post@n5.nabble.com> Subject: Re: Using variables in select Date: Fri, 12 Aug 2011 17:03:52 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.15 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.811, STOX_REPLY_TYPE=0.439, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201108/36 X-Sequence-Number: 35704 How do you access your database? Through some client application like psql ? Through some other mean? The query you included is the query you wanna perform against ur table? Or was it just an example? Do you wanna avoid having to write the complete query on the command line? If so, you sound like you need a function something like CREATE FUNCTION customer_table(int) RETURNS customer_table AS $$ SELECT COUNT(DISTINCT costumer_id),AVG(price) FROM customer_table WHERE productid = $1 $$ LANGUAGE SQL; HTH Best, Oliveiros ----- Original Message ----- From: "tlund79" To: Sent: Friday, August 12, 2011 12:05 PM Subject: [SQL] Using variables in select > Hi, > > Firstly; I'm not a developer, but a business developer and statistics guy. > This means that I'm happy using "basic" selects to gather information for > analysis. > > One thing that could really efficiate my work is using variables, let's > say > I have a table with different orders; > > |customer_id|productid|price| > > What I really want is to create a general query where I could easily > substitute productid. > > // > > declare variable --> productid = 10 > > select count(distinct customer_id), avg(price) from customer_table where > productid= > > \\ > > Is there a way of doing this without getting involved with heavy > programming? > > > > Thank you and applogies if this is a ridicioulus question! > > -- > View this message in context: > http://postgresql.1045698.n5.nabble.com/Using-variables-in-select-tp4692865p4692865.html > Sent from the PostgreSQL - sql mailing list archive at Nabble.com. > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql