X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id BAB71D1B8B3 for ; Sat, 20 Sep 2003 13:40:42 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 48161-05 for ; Sat, 20 Sep 2003 10:40:14 -0300 (ADT) Received: from hotmail.com (sea2-f26.sea2.hotmail.com [207.68.165.26]) by svr1.postgresql.org (Postfix) with ESMTP id 69DF6D1B547 for ; Sat, 20 Sep 2003 10:40:10 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sat, 20 Sep 2003 06:40:14 -0700 Received: from 80.205.253.69 by sea2fd.sea2.hotmail.msn.com with HTTP; Sat, 20 Sep 2003 13:40:13 GMT X-Originating-IP: [80.205.253.69] X-Originating-Email: [martinkuria@hotmail.com] From: "Martin Kuria" To: ch@rodos.fzk.de, pgsql-sql@postgresql.org Subject: sub query Date: Sat, 20 Sep 2003 16:40:13 +0300 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 20 Sep 2003 13:40:14.0336 (UTC) FILETIME=[B86D7800:01C37F7C] X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/224 X-Sequence-Number: 15202 Hi again I have this problem when I try to run this query, how can I rewrite it for it to work. SELECT o.item_order_num,SUM(o.item_quantity + o.item_product_id) As total, o.item_status FROM soko_product p, soko_ordered_item o WHERE p.product_id = o.item_product_id GROUP BY o.item_order_num ORDER BY o.item_order_num; Error: Attribute o.item_status must be GROUPED OR USE IN an aggregate function Please do advice thanks again Kind regards +-----------------------------------------------------+ | Martin W. Kuria (Mr.) martin.kuria@unon.org +----------------------------------------------------+ >From: Christoph Haller >To: pgsql-sql@postgresql.org >CC: martinkuria@hotmail.com >Subject: Re: [SQL] sub query >Date: Wed, 17 Sep 2003 10:54:49 +0200 > > > > > > Hi I have this problem, when I try to run this query: > > > > > > SELECT MAX(d), host_position FROM (SELECT host_position, > > > COUNT(host_position) as d FROM sss_host GROUP BY host_position) as >e; > > > > > > am getting and ERROR: Attribute e.host_position must be GROUPed or > > used in > > > an aggregate function. > > > > > > Please to advice what could be the problem and how can I rewrite it >to > > work > > > thanks in advance. > > > > > As the error message says: e.host_position must be GROUPed > > > > so (supposing you want a one row result showing the maximum count) > > > > SELECT MAX(e.d), e.host_position FROM (SELECT host_position, > > COUNT(host_position) as d FROM sss_host GROUP BY host_position) as e > > GROUP BY e.host_position ORDER BY 1 LIMIT 1; > > > > should match your intentions. > > >Just thought about another (less complex) way: > >SELECT COUNT(host_position), host_position FROM >sss_host GROUP BY host_position ORDER BY 1 DESC LIMIT 1; > >Regards, Christoph > > > >---------------------------(end of broadcast)--------------------------- >TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly _________________________________________________________________ Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail