From: | Uro Gruber <uros(at)sir-mag(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Help with JOINING 3 tables |
Date: | 2001-01-08 00:36:21 |
Message-ID: | 19648562028.20010108013621@sir-mag.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi!
I have this 3 tables:
CREATE TABLE clients (
client_id CHAR(32) NOT NULL,
created TIMESTAMP DEFAULT 'now' NOT NULL,
modified TIMESTAMP DEFAULT 'now' NOT NULL,
username VARCHAR(12) NOT NULL,
.
.
PRIMARY KEY (client_id)
);
client_id username
1 u1
2 u2
3 u3
CREATE TABLE statistics (
created TIMESTAMP,
host INET NOT NULL,
stat_type CHAR(1), --possible value (v,c)
banner_id INTEGER NOT NULL,
);
stat_type banner_id
v 1
v 1
v 5
c 5
v 3
v 4
c 4
v 6
c 6
v 2
v 2
c 2
CREATE TABLE banners (
banner_id SERIAL NOT NULL,
created TIMESTAMP DEFAULT 'now' NOT NULL,
modified TIMESTAMP DEFAULT 'now' NOT NULL,
banner TEXT NOT NULL,
.
.
client_id VARCHAR(32) NOT NULL,
PRIMARY KEY (banner_id)
);
banner_id banner client_id
1 b1 1
2 b2 2
3 b3 1
4 b4 3
5 b5 1
6 b6 3
I want to count how many v or c are in table statistics for some
client.
something like this:
client_id views clicks
1 4 1
2 2 1
3 2 2
Is is possible to write some function or is it possible to do this
with some complex join or smth. I'm trying this for hours... no
luck:((
please help!
Thanks,
--
Uroš
From | Date | Subject | |
---|---|---|---|
Next Message | Adam Haberlach | 2001-01-08 03:31:09 | Re: Warning: PostgresSQL query failed????` |
Previous Message | gianpaolo | 2001-01-07 22:49:07 | Re: Passing tables as parameter |