← Practice

Клиенты с действующим счётом по месяцам 2025

Questions like this come up in interviews at Точка

Level: MiddleTopic: Dates and time series100 XP

Instructions

Счёт действует в день X, если opened_at не позже X, а closed_at равен NULL или не раньше X. Для каждого месяца 2025 года посчитайте clients_cnt — число клиентов, у которых хотя бы один счёт действовал хотя бы в один день этого месяца. Постройте ряд из 12 месяцев и проверяйте пересечение периода действия счёта с месяцем. Выведите month — первый день месяца (тип date) и clients_cnt. Сортировка по month.

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