an difficult SQL

Поиск
Список
Период
Сортировка
От Rafal Pietrak
Тема an difficult SQL
Дата
Msg-id d0c374e1-4e50-6b1f-21f0-b16564aa934b@ztk-rp.eu
обсуждение исходный текст
Ответы Re: an difficult SQL  (Thiemo Kellner <thiemo@gelassene-pferde.biz>)
Список pgsql-general
Hi Everybody,

I was wondering if anybody here could help me cook up a query:

1. against a list of events (like an activity log in the database). The 
list is a single table: create table events (tm timestamp, user int, 
description text).

2. of which the output would be sorted in such a way, that:
2.1 most recent event would "select" most recent events of that same 
user, and displayed in a group (of say 10) of them (in "tm" order).

2.2 going through the events back in time, first event of ANOTHER user 
selects next group, where (say 10) most recent events of that OTHER user 
is presented.

2.3 next most recent event of yet another user selects yet another group 
to display and this selection process goes on, up to a maximum of (say 
20) users/groups-of-their-events.

2.4 after that, all other events are selected in tm order.

This is to present most recent telephone activities grouped by most 
recent subscribers so that the dashboard doesn't get cluttered with 
information but allows for an overview of other activity of most recent 
users.

I tend to think, that it's a problem for a window function ... but I've 
stumbled on the problem how to limit the window "frame" to just a few 
(say 10) events within the "window" and have all the rest returned as 
"tail" of the query.

BTW: the eventlog table is big. (and partitioned).

Any help appreciated.

-R



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

Предыдущее
От: Bruno Wolff III
Дата:
Сообщение: Re: Postgres 15 upgrades and template1 public schema
Следующее
От: Thiemo Kellner
Дата:
Сообщение: Re: an difficult SQL