pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nikolaj Lundsgaard <Nikolaj@kampsax.dtu.dk>
To: pgsql-sql@postgresql.org
Subject: Sv: how to build this query ??? Please help !!!
Date: Wed, 3 Jan 2001 16:40:54 +0100
Message-ID: <008701c0759b$8ebe7100$8fd426c0@commando.kampsax.dtu.dk> (raw)

Something like this oughtta work (not tested)

SELECT a_nr, 
(SELECT count(*) FROM cylinders WHERE z_a_nr = a_nr) AS #cylinder,
(SELECT count(*) FROM cylinders WHERE z_a_nr = a_nr AND z_status = 'zdr') AS #zdr,
(SELECT count(*) FROM cylinders WHERE z_a_nr = a_nr AND z_status = 'zcu') AS #zcu,
(SELECT count(*) FROM cylinders WHERE z_a_nr = a_nr AND z_status = 'zcr') AS #zcr,
product, state
FROM orders


/Nikolaj

-----Oprindelig meddelelse-----
Fra: juerg.rietmann@pup.ch <juerg.rietmann@pup.ch>
Til: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Dato: 3. januar 2001 16:16
Emne: [SQL] how to build this query ??? Please help !!!


>Hello there
>
>I have a problem, building a query. Who can help ?
>I use postgreSQL 7.0.3.
>
>Thanks for any help and suggestions ... jr
>
>orders
>a_nr ¦ product ¦ state
>-----------------------------
>11   ¦ tp      ¦ aaaa
>12   ¦ fi      ¦ bbbb
>13   ¦ tp      ¦ cccc
>14   ¦ ok      ¦ eeee
>15   ¦ dm      ¦ aaaa
>
>cylinders
>z_a_nr   ¦     z_status
>------------------------------
>11     ¦  zdr
>11     ¦  zdr
>12     ¦  zdr
>12     ¦  zcu
>13     ¦  zdr
>13     ¦  zcu
>13     ¦  zcu
>13     ¦  zcr
>15     ¦  zcu
>15     ¦  zcu
>15     ¦  zdr
>
>I need a query for the following output :
>
>a_nr   ¦  #cylinder #zdr #zcu #zcr product    state
>----------------------------------------------------------------------
>11        2         2    0    0    dm         aaaa
>12        2         1    1    0    tp         aaaa
>13        4         1    2    1    fi         bbbb
>14        0         0    0    0    ok         eeee
>15        3         1    2    0    dm         aaaa
>
>
>
>
>
>============================================
>PFISTER + PARTNER, SYSTEM - ENGINEERING AG
>Juerg Rietmann
>Grundstrasse 22a
>6343 Rotkreuz
>Switzerland
>
>phone: +4141 790 4040
>fax: +4141 790 2545
>mobile: +4179 211 0315
>============================================
>
>




view thread (12+ messages)  latest in thread

Message-ID: <008701c0759b$8ebe7100$8fd426c0@commando.kampsax.dtu.dk>
Permalink:  ../008701c0759b$8ebe7100$8fd426c0@commando.kampsax.dtu.dk/
Also on:    postgresql.org/message-id/008701c0759b$8ebe7100$8fd426c0@commando.kampsax.dtu.dk

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: Nikolaj@kampsax.dtu.dk
  Subject: Re: how to build this query ??? Please help !!!
  In-Reply-To: <008701c0759b$8ebe7100$8fd426c0@commando.kampsax.dtu.dk>
  References: <008701c0759b$8ebe7100$8fd426c0@commando.kampsax.dtu.dk>

* 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