query like this???

Поиск
Список
Период
Сортировка
От Akbar
Тема query like this???
Дата
Msg-id 1114618368.6831.7.camel@localhost.localdomain
обсуждение исходный текст
Ответы Re: query like this???  (Michael Fuhr <mike@fuhr.org>)
Список 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 по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Poor-man's enumeration type
Следующее
От: Greg Lindstrom
Дата:
Сообщение: Inserting Using RowType