← Practice

Какой счёт клиенты открывают первым, вторым, третьим

Questions like this come up in interviews at Сбер

Level: MiddleTopic: Window functions100 XP

Instructions

Пронумеруйте счета каждого клиента по порядку открытия: по opened_at, при равенстве — по id (первый открытый счёт получает номер 1). Постройте сводку по типу счёта (type): as_first — у скольких клиентов счёт этого типа стоит под номером 1, as_second — под номером 2, as_third — под номером 3. Выведите type, as_first, as_second, as_third. Порядок строк не важен.

not translated yet

Hints

Each next one is more detailed and costs more

Log in to open hints

Query

Result

Click Run to see the query result, or Check to submit your solution.

Dataset schema

accounts.client_id (0…N) ↔ clients.id (1…1)transactions.account_id (0…N) ↔ accounts.id (1…1)accountsPKidintegerFKclient_idintegerclientsPKidintegertransactionsPKidintegerFKaccount_idinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneaccounts.client_id → clients.id
  • N:1Many-to-onetransactions.account_id → accounts.id

Table data

PostgreSQL

Select a table in the diagram or list to view its rows.

Dataset schema