Re: total and partial sums in the same query??

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: total and partial sums in the same query??
Дата
Msg-id CAKFQuwYQyHHgtFOhZ7PpECPLO61LANtt7WdYng=SmvLBDKCubg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: total and partial sums in the same query??  (Iuri Sampaio <iuri.sampaio@gmail.com>)
Список pgsql-sql
On Sat, Oct 10, 2020 at 8:28 AM Iuri Sampaio <iuri.sampaio@gmail.com> wrote:
So, feel free whether to go deeper continuing this discussion 

Specifically:

WITH v_normalized AS (SELECT split_part(description, ' ', 25) AS type1, EXTRACT(MONTH FROM creation_date) AS month FROM qt_vehicle_ti)
SELECT type1, count(*) as count_total, count(*) filter (where month=10) AS count_m10 FROM v_normalized GROUP BY type1;

There is no benefit to having a join here.

Using WITH to compute v_normalized in just this query works but I suspect you will find you are writing something like that a lot which suggests it, or rather something similar but a bit more general, should be computed using CREATE VIEW.

David J.

В списке pgsql-sql по дате отправления:

Предыдущее
От: Iuri Sampaio
Дата:
Сообщение: Re: total and partial sums in the same query??
Следующее
От: Martin Norbäck Olivers
Дата:
Сообщение: get counts of multiple field values in a jsonb column