pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: knut.suebert@web.de
To: pgsql-sql@postgresql.org
Subject: Re: Recursive select
Date: Sun, 4 Nov 2001 18:03:06 +0100
Message-ID: <20011104180306.A2309@cascal.vtb> (raw)
In-Reply-To: <c0d87ec0.0110311714.3c2d0de8@posting.google.com>
References: <20011029154754.A11730@cc.usu.edu>
	<c0d87ec0.0110311714.3c2d0de8@posting.google.com>

--CELKO-- schrieb:

> Another way of representing trees is to show them as nested sets. 

Good evening, 

that's what I needed!

To limit the result to entries below one node, I'd use something like

  SELECT P1.lft, COUNT(P2.emp) AS indentation, P1.emp 
    FROM Personnel AS P1, Personnel AS P2 
    WHERE P1.lft BETWEEN P2.lft AND P2.rgt
      AND p1.lft>(SELECT lft FROM personnel WHERE emp='Chuck')
      AND p1.rgt<(SELECT rgt FROM personnel WHERE emp='Chuck')
    GROUP BY P1.emp, p1.lft ORDER BY P1.lft;

   lft | indentation |    emp     
  -----+-------------+------------
     5 |           3 | Donna     
     7 |           3 | Eddie     
     9 |           3 | Fred      
  (3 rows)

for emp='Albert' it returns

   lft | indentation |    emp     
  -----+-------------+------------
     2 |           2 | Bert      
     4 |           2 | Chuck     
     5 |           3 | Donna     
     7 |           3 | Eddie     
     9 |           3 | Fred      
  (5 rows)

My question is, how to limit this result to (Albert's indentation)+1?

Thanks,
Knut Sübert



view thread (11+ messages)

Message-ID: <20011104180306.A2309@cascal.vtb>
Permalink:  ../20011104180306.A2309@cascal.vtb/
Also on:    postgresql.org/message-id/20011104180306.A2309@cascal.vtb

 · 

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: knut.suebert@web.de
  Subject: Re: Recursive select
  In-Reply-To: <20011104180306.A2309@cascal.vtb>

* 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