pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Abdul Wahab Dahalan <wahab@mimos.my>
Cc: pgsql-sql@postgresql.org
Subject: Re: Need Help
Date: Thu, 13 Nov 2003 23:11:53 -0600
Message-ID: <20031114051153.GB29956@wolff.to> (raw)
In-Reply-To: <3FB42A2F.20801@mimos.my>
References: <3FB42A2F.20801@mimos.my>

On Fri, Nov 14, 2003 at 09:04:47 +0800,
  Abdul Wahab Dahalan <wahab@mimos.my> 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.



view thread (35+ messages)  latest in thread

Message-ID: <20031114051153.GB29956@wolff.to>
Permalink:  ../20031114051153.GB29956@wolff.to/
Also on:    postgresql.org/message-id/20031114051153.GB29956@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, wahab@mimos.my
  Subject: Re: Need Help
  In-Reply-To: <20031114051153.GB29956@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox