Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fakTI-0003w5-ET for pgsql-general@arkaria.postgresql.org; Wed, 04 Jul 2018 16:17:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fakTG-0007JY-JU for pgsql-general@arkaria.postgresql.org; Wed, 04 Jul 2018 16:17:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fakTG-0007JM-Bv for pgsql-general@lists.postgresql.org; Wed, 04 Jul 2018 16:17:34 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fakTC-0006iZ-CL for pgsql-general@postgresql.org; Wed, 04 Jul 2018 16:17:33 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id AF02BDD7371F for ; Wed, 4 Jul 2018 09:17:27 -0700 (MST) Date: Wed, 4 Jul 2018 09:17:27 -0700 (MST) From: legrand legrand To: pgsql-general@postgresql.org Message-ID: <1530721047714-0.post@n3.nabble.com> In-Reply-To: References: <3524c35d-e566-9bad-e4bd-d493f05f2d4d@gmail.com> Subject: Re: Return select statement with sql case statement MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello, sorry your description is not clear ... why do you use a GROUP BY on product without aggregation function min, max, sum ? where is defined numberOfPremiumDays ? may be using UNION can solve your problem: select numberOfPremiumDays, product_id, premium_price, period_price from product, PremiumDays where occupation_type_id = 1 and numberOfPremiumDays = date_part('day', ('2018-11-05'::timestamp) - ('2018-11-01'::timestamp)) UNION ALL select numberOfPremiumDays, product_id, classic_price, period_price from product1, PremiumDays where occupation_type_id = 1 and numberOfPremiumDays != date_part('day', ('2018-11-05'::timestamp) - ('2018-11-01'::timestamp)) Regards PAscal -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html