Re: nested select within a DISTINCT block

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: zqzuk <ziqi(dot)zhang(at)hotmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: nested select within a DISTINCT block
Date: 2006-09-22 17:28:41
Message-ID: 20060922172841.GB3193@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Sep 14, 2006 at 05:02:25 -0700,
zqzuk <ziqi(dot)zhang(at)hotmail(dot)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(*).

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Doug Hyde 2006-09-22 19:13:46 How to autoincrement a primary key...
Previous Message Scott Marlowe 2006-09-22 14:56:02 Re: Group by minute