SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed

New conversation

What can I help with?

Ask about this page, get a hint on a challenge, or explore SQL concepts.

I know what's on this page and can give answers grounded in SQL Boy content.

Current page

Percentage Of Users Attended

/challenges/percentage-of-users-attended

Usage status will load after login
SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog
SQL Challenges/Percentage of Users Attended
Challenge DetailMediumReviewed 2026-04-20

Percentage of Users Attended

Find the percentage of the users registered in each contest rounded to two decimals. Return the result table ordered by percentage in descending order and contest_id in ascending order.

AggregationSubqueries

This challenge now meets the current minimum standard for sitemap inclusion and independent indexing.

2026-01-03Medium

Percentage of Users Attended

Find the percentage of the users registered in each contest rounded to two decimals. Return the result table ordered by percentage in descending order and contest_id in ascending order.

Available Tables:
SQL Editor
Loading...

What This Challenge Is Testing

This is a denominator-selection problem. Teams frequently misstate metrics by using the wrong population baseline, and contest participation, feature adoption, and campaign reach all depend on comparing a subgroup against the correct total population.

Topic Tags

AnalyticsAggregations

Schema At A Glance

users
user_iduser_name
register
contest_iduser_id

Solution Approaches

01

Aggregate registrations against the global user count

SELECT
  contest_id,
  ROUND(COUNT(user_id) * 100.0 / (SELECT COUNT(*) FROM users), 2) AS percentage
FROM register
GROUP BY contest_id
ORDER BY percentage DESC, contest_id ASC

This is the shortest correct solution. The subquery provides the total user population once, and each contest group divides its registration count by that same denominator.

02

Lift the user count into a CTE first

WITH totals AS (
  SELECT COUNT(*) AS total_users
  FROM users
)
SELECT
  r.contest_id,
  ROUND(COUNT(r.user_id) * 100.0 / t.total_users, 2) AS percentage
FROM register r
CROSS JOIN totals t
GROUP BY r.contest_id, t.total_users
ORDER BY percentage DESC, r.contest_id ASC

The CTE version is useful when the denominator becomes more complex later, such as active users only or users from a filtered segment. It keeps the baseline population explicit and auditable.

Common Pitfalls

A common mistake is dividing by the number of registrations in the same contest instead of by the total number of users. Another is forgetting decimal multiplication, which can cause integer truncation and return 0 or a rounded-down percentage.

Frequently Asked Questions

Why is the total user table the denominator instead of total registrations?

Because the metric asks what percentage of all users registered for each contest. Total registrations answers a different question and would make every contest look artificially complete.

What concept does this map to outside contests?

It maps to feature adoption and participation metrics: how much of a total user population engaged with a specific event, campaign, or product feature.

Concept Guides

Use these guides when you want the fuller explanation behind the SQL pattern this challenge is testing.

Building Conversion Funnels in SQL

Master funnel analysis with SQL. Learn how to track user journeys from landing page to purchase and identify where you are losing customers.

SQL Conditional Aggregation: Beyond Basic GROUP BY

Turn multiple queries into one with conditional aggregation. Learn how CASE WHEN inside aggregate functions creates powerful single-query reports and pivot tables.

SQL Aggregate Functions: COUNT, SUM, AVG, MIN, MAX Explained

Master SQL aggregate functions with practical examples. Learn when and how to use COUNT, SUM, AVG, MIN, and MAX effectively.

Topic Hubs

If this problem exposed a deeper weakness, use a topic hub to move through a curated cluster instead of random article hopping.

Analytics

Analytics SQL and business metrics

A practical cluster for cohorts, funnels, customer value, and the kinds of reporting questions teams actually ask every week.

Advanced SQL

Advanced query patterns

Use this path when you are moving beyond beginner SELECT queries into CTEs, window functions, and conditional logic.

Practice Path

If you want the rotating practice flow, open this same question from the daily stream. If you want interview-style packaging, continue into the interview pool after this rep.

Back to ChallengesOpen In DailyBrowse Interviews

Related Challenges

Trips and UsersHard

Compute daily cancellation rate after excluding any trip where either the client or driver is banned.

Monthly Transactions IMedium

Roll monthly transaction reporting into one query while splitting total volume from approved volume by country.

Immediate Food Delivery IIMedium

Measure what share of customers got an immediate delivery on their first-ever order instead of across all orders.

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed