Author Sales Metrics
Start Timer
0:00:00
Let’s say we work at Meta on a marketplace where authors sell books. Write a single query that returns the total number of authors, the percentage of authors whose website contains .com, and the percentage of authors who have never sold a book.
Rules
- Express both percentages on a 0 to 100 scale, rounded to 2 decimal places.
- .com can appear anywhere in website, in any letter case, so Alice.COM/home and shop.company.org both count.
- A missing or empty website does not contain .com.
- Every author counts toward the total, including authors with no sales.
Example:
Input:
authors table
| Column | Type |
|---|---|
id |
INTEGER |
name |
VARCHAR |
website |
VARCHAR |
sales table
| Column | Type |
|---|---|
id |
INTEGER |
author_id |
INTEGER |
book_title |
VARCHAR |
sold_at |
DATETIME |
Output:
| Column | Type |
|---|---|
total_authors |
INTEGER |
pct_com_website |
FLOAT |
pct_never_sold |
FLOAT |
.
.
.
.
.
.
.
.
.
Comments