Re: how to use aggregate functions in this case

Поиск
Список
Период
Сортировка
От BladeOfLight16
Тема Re: how to use aggregate functions in this case
Дата
Msg-id CA+=1U=VgJ-Mb_cNe6mANCT71ZTkXtUxm4Sr=AiKViHKbhAYN3Q@mail.gmail.com
обсуждение исходный текст
Ответ на Re: how to use aggregate functions in this case  (BladeOfLight16 <bladeoflight16@gmail.com>)
Ответы Re: how to use aggregate functions in this case  (David Johnston <polobo@yahoo.com>)
Список pgsql-general
On Sun, Aug 25, 2013 at 8:36 PM, BladeOfLight16 <bladeoflight16@gmail.com> wrote:
This appears to be some kind of equal interval problem.

SELECT  v_rec1.user,
        WIDTH_BUCKET(v_rec_fts.lev, 0, 100, 4) AS bucket
        COUNT(*) as count,
FROM v_rec2
GROUP BY user, bucket;

(Untested, but this should be the gist.)

Bucket 1 would be 0 to 25, bucket 2 is 25 to 50, 3 is 50 to 75, 4 is 75 to 100. If you really need to change the bucket number to some kind of text, you can probably nest this query inside another that uses a CASE to pick the text based on on the bucket number.

Good luck.

Then again, I guess you don't need a nested query.

SELECT  v_rec1.user,
        CASE WIDTH_BUCKET(v_rec_fts.lev, 0, 100, 4)
              WHEN 1 THEN '0 to 25'
              WHEN 2 THEN '25 to 50'
              WHEN 3 THEN '50 to 75'
              WHEN 4 THEN '75 to 100'
              ELSE 'But how?'
        END CASE AS quarter_percentage
        COUNT(*) as count,
FROM v_rec2
GROUP BY user, quarter_percentage;

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

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: batch insertion
Следующее
От: 高健
Дата:
Сообщение: Re: What is the relationship between checkpoint and wal