From: | Frodo Larik <lists(at)elasto(dot)nl> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Query Question |
Date: | 2005-09-27 10:20:05 |
Message-ID: | 43391CD5.9000304@elasto.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi All,
I have the following simplified setup. A client has 2 products: 'vbp'
and 'year_balance', but a client has also workers who have a product,
named 'ib'. A client can have multiple workers.
-- clients
CREATE TABLE clients (
id serial NOT NULL PRIMARY KEY,
name text NOT NULL,
vbp boolean DEFAULT 'f'::bool NOT NULL, -- product 'vbp'
year_balance boolean DEFAULT 'f'::bool NOT NULL -- product
'year_balance'
);
-- workers
CREATE TABLE workers (
id serial NOT NULL PRIMARY KEY,
client_id integer NOT NULL REFERENCES clients(id),
ib boolean DEFAULT 'f'::bool NOT NULL -- product 'ib'
);
There one thing I like to know. What products are active for a client
(clients.id) or for all clients:
I don't know what query I can use to accomplish this, but I know I would
like to have results like this
SELECT <<some_query_magic>>
clients.name | workers.ib | clients.vbp | clients.year_balance
----------------+--------------+--------------+-------------------------
client a | t | f | f
client b | f | t | t
It is possible that a client has zero or more workers, I want to know if
one of the workers has workers.ib = 't' set if this is true I like to
have 't' returned else a 'f'
Is this possible in a single query?
Sincerely,
Frodo Larik
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2005-09-27 10:45:23 | Re: Restore xxxxx.backup database |
Previous Message | Gábor Farkas | 2005-09-27 09:58:42 | Re: change db encoding? |