#211

Bookstore Author Statistics Analysis

MEDIUMAggregation & WindowsPOSTGRESQL

Problem Description

You are building an author-health dashboard for a content marketplace analytics pipeline. The pipeline ingests author registration data, book catalog records, and customer transaction history to produce a single-row summary of three key metrics. **Metric 1 — Total Authors:** - Count every row in the `author` table regardless of activity **Metric 2 — `.com` Website Authors:** - Count authors whose `website_url` contains the substring `'.com'` anywhere in the string - This is a substring check, not a suffix check: `author.community` qualifies because it contains `'.com'` - `NULL` website URLs do not match and must not be counted - Return the raw count (not a percentage) **Metric 3 — No-Sales Percentage:** - An author "made a sale" if at least one of their books appears in the `transaction` table - Path: `author` → `book` (via `author_id`) → `transaction` (via `book_id`) - Authors with no books, or books with no transactions, count as having no sales - Calculate as: `(authors_with_no_sales / total_authors) * 100`, rounded to 2 decimal places **Output:** a single row with columns `total_authors`, `com_website_authors`, `no_sales_percentage`.

Topics

aggregationstring functions

Asked at Companies

meta

Solve This Problem

Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.

Start Solving →