← Dates and time series

Clients aged 40–55 on May 31, 2025: Казань

Level: Junior50 XP

Instructions

A client's age on May 31, 2025 is the number of full years between birth_date and that date (age(May 31, 2025, birth_date), years only). Consider clients from the city 'Казань' (clients.city) whose age on that date is from 40 to 55 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