Join query help

From: "Raj A" <raj(dot)ayappan(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Join query help
Date: 2007-08-18 06:11:30
Message-ID: ddcb1c340708172311s47a565a5t49ffb8c14acac7d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Hi, We have the following three tables.

safety=> SELECT record_id, record_date FROM record;
record_id | record_date
-----------+------------------------
1 | 2007-07-23 11:30:37+10
2 | 2007-07-27 11:30:14+10
3 | 2007-07-17 13:15:03+10
(3 rows)

safety=> SELECT observation_id, record_id, score_id FROM observation;
observation_id | record_id | score_id
----------------+-----------+----------
3240 | 1 | 1
3239 | 1 | 1
3238 | 1 | 2
3237 | 1 | 1
2872 | 2 | 1
2869 | 2 | 2
2870 | 2 | 1
2871 | 2 | 1
3218 | 3 | 2
3217 | 3 | 1
(10 rows)

safety=> SELECT * FROM SCORE;
score_id | score_description
----------+-------------------
0 | NA
1 | SAFE
2 | AT RISK
(3 rows)

What query do I write to generate the following?

week_no | count(record_id | count(observation_id) | sum(score_id) where = '1'
2007, 30 | 2 | 8 | 6
2007, 29 | 1 | 2 | 1

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Prasanna Mavinakuli 2007-08-18 06:26:01 Problem with pg_hba.conf?
Previous Message Andrej Ricnik-Bay 2007-08-18 05:42:53 Re: I get a error msg when i try to connect to the DB

Browse pgsql-sql by date

  From Date Subject
Next Message Franz Mühlbauer 2007-08-18 09:26:06 Re: Limited number of polygon function arguments
Previous Message novice 2007-08-18 05:35:12 Join query help