← Practice

Clients aged 51–60 on January 31, 2025: Москва

Level: JuniorTopic: Dates and time series50 XP

Instructions

A client's age on January 31, 2025 is the number of full years between birth_date and that date (age(January 31, 2025, birth_date), years only). Consider clients from the city 'Москва' (clients.city) whose age on that date is from 51 to 60 years inclusive. Group them by segment (clients.segment) and output segment, clients_cnt, the number of clients, and avg_age, the average age on that date, rounded to 1 decimal place. Do not output segments without matching clients. Row order does not matter.

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