query like this??? - Mailing list pgsql-novice

From Akbar
Subject query like this???
Date
Msg-id 1114618368.6831.7.camel@localhost.localdomain
Whole thread Raw
Responses Re: query like this???
List pgsql-novice
CREATE TEMP table stupid (
    datestock date,
    dummy int
);

INSERT INTO stupid VALUES( '2005-4-1', 3 );
INSERT INTO stupid VALUES( '2005-5-1', 3 );
INSERT INTO stupid VALUES( '2005-5-4', 3 );
INSERT INTO stupid VALUES( '2005-7-5', 3 );
INSERT INTO stupid VALUES( '2005-7-1', 3 );
INSERT INTO stupid VALUES( '2005-4-7', 3 );
INSERT INTO stupid VALUES( '2005-4-9', 3 );

query like this:
SELECT extract (month FROM datestock::timestamp) AS month, sum(dummy)
FROM stupid
WHERE extract (month FROM datestock::timestamp) BETWEEN 2 AND 8
GROUP BY extract (month FROM datestock::timestamp)
ORDER BY extract (month FROM datestock::timestamp)

give this:
month     sum
-----     ---
4         9
5         6
7         6

I want to ask what query will give me this output:
month     sum
-----     ---
2         0
3         0
4         9
5         6
6         0
7         6
8         0

but with this condition:
WHERE extract (month FROM datestock::timestamp) BETWEEN 2 AND 8


pgsql-novice by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Poor-man's enumeration type
Next
From: Greg Lindstrom
Date:
Subject: Inserting Using RowType