pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: zqzuk <ziqi.zhang@hotmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: nested select within a DISTINCT block
Date: Fri, 22 Sep 2006 12:28:41 -0500
Message-ID: <20060922172841.GB3193@wolff.to> (raw)
In-Reply-To: <6304397.post@talk.nabble.com>
References: <6304397.post@talk.nabble.com>

On Thu, Sep 14, 2006 at 05:02:25 -0700,
  zqzuk <ziqi.zhang@hotmail.com> wrote:
> 
> Hi, here i have a problem with this task...
> 
> I have a table "cancellation" which stores cancelled bookings and details of
> charges etc
> and a table "bookings" which stores details of bookings, for example:
> 
> cancellation(cancellation_id, booking_id, charge)
> booking(booking_id, customer_id, product_package_id, details)
> 
> in the query, i wish to find, how many customers have booked for each
> product_package_id. if there were 3 bookings for product_package_id=1, and
> all these are cancelled and therefore exist in cancellation, then the query
> result shoud display something like
> 
> could anyone give any hints please, many thanks !

Left join booking and cancellation, select rows where cancellation_id
IS NULL, GROUP BY either booking_id, and return that booking_id and count(*).



view thread (2+ messages)

Message-ID: <20060922172841.GB3193@wolff.to>
Permalink:  ../20060922172841.GB3193@wolff.to/
Also on:    postgresql.org/message-id/20060922172841.GB3193@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, ziqi.zhang@hotmail.com
  Subject: Re: nested select within a DISTINCT block
  In-Reply-To: <20060922172841.GB3193@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