Skip to content
BytePatterns

Emails Used More Than Once

EasySQL#group-by#having~10m

Problem

A table account(id, email) holds one row per sign-up, and a signup form without a uniqueness check has let some emails in several times. Write a query that returns every email that appears on more than one account, with the number of accounts that use it, as columns email and uses, sorted by email. Emails are compared exactly as stored.

Examples

Input:  account = [(1, "a@x.io"), (2, "b@x.io"), (3, "a@x.io"), (4, "c@x.io"), (5, "b@x.io"), (6, "a@x.io")]
Output: [("a@x.io", 3), ("b@x.io", 2)]
Why:    c@x.io is used once, so it is not a duplicate
Input:  account = [(1, "a@x.io"), (2, "b@x.io")]
Output: []
Why:    edge case, no email repeats, so no row comes back

Hints

0 / 3

Stuck on the idea rather than the code? Aggregations & GROUP BY covers it.