First and Last Seen

SQL practice problem 19 of 67 · Aggregation · Easy · 10 coins for your first accepted solve

For every player who logged in, return player_id, first_login, last_login and the number of logins. Row order does not matter.

Schema

CREATE TABLE players (
  id         INT PRIMARY KEY,
  name       TEXT NOT NULL,
  country    TEXT,            -- NULL = unknown
  level      INT NOT NULL,
  joined_on  DATE NOT NULL,
  mentor_id  INT              -- another player's id, or NULL
);

CREATE TABLE logins (
  player_id  INT NOT NULL REFERENCES players(id),
  logged_at  TIMESTAMP NOT NULL
);

Write your query in the browser, run it on the sample data, then submit it against hidden test data.

Previous: Repeat Buyers · Next: Big Spenders · All problems