X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 9ADF7D1B502 for ; Fri, 14 Nov 2003 05:13:52 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 17139-02 for ; Fri, 14 Nov 2003 01:13:21 -0400 (AST) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 56B2DD1B531 for ; Fri, 14 Nov 2003 01:13:20 -0400 (AST) Received: (qmail 30080 invoked by uid 500); 14 Nov 2003 05:11:53 -0000 Date: Thu, 13 Nov 2003 23:11:53 -0600 From: Bruno Wolff III To: Abdul Wahab Dahalan Cc: pgsql-sql@postgresql.org Subject: Re: Need Help Message-ID: <20031114051153.GB29956@wolff.to> Mail-Followup-To: Abdul Wahab Dahalan , pgsql-sql@postgresql.org References: <3FB42A2F.20801@mimos.my> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3FB42A2F.20801@mimos.my> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/163 X-Sequence-Number: 15978 On Fri, Nov 14, 2003 at 09:04:47 +0800, Abdul Wahab Dahalan wrote: > Hi! > > If I've a table like this > > kk kj pngk vote > 01 02 a 12 > 01 02 b 10 > 01 03 c 5 > > and I want to have a query so that it give me a result as below. > > The condition is for each record with the same kk and kj > but difference pngk will be give a mark *; > [In this example for record 1 and record 2 we have same kk=01 and kj=02 > but difference pngk a and b so we give * for the mark] > > > kk kj pngk vote mark > 01 02 a 12 * > 01 02 b 10 * > 01 03 c 5 > > How should I write the query? You could do something like: select a.kk, a.kj, a.pngk, a.vote, b.star from table a left join (select '*' star, kk, kj from table group by kk, kj having count(*) > 1) b on (a.kk = b.kk and a.kj = b.kj); I didn't test this so there might be a syntax problem, but it should make it clear how to do what you want.