Topfolio
Career TracksFree CoursesPracticeWork ExperienceProjects
For Employers
Start Free
Topfolio

Learn data analytics online. Real skills, real projects, real community.

courses

  • Career Tracks
  • Work Experience
  • Best Data Analyst Course in India
  • SQL Fundamentals
  • SQL Advanced
  • Python for Data
  • Micro Free Courses

practice

  • SQL Fundamentals Interview Test
  • SQL Advanced Coding Test
  • All Practice Tests

resources

  • How to Become a Data Analyst
  • SQL Interview Questions
  • Data Analyst Salary Guide
  • Free Datasets for Practice
  • SQL vs NoSQL Guide
  • Data Analyst vs Data Engineer vs Data Scientist

employers

  • Enterprise Screening
  • AI Proctoring Demo
  • Volume Pricing
  • Employer Portal

company

  • About
  • Terms
© 2026 Topfolio. All rights reserved.Made with ❤️ for aspiring analysts
Topfolio
Career TracksFree CoursesPracticeWork ExperienceProjects
For Employers
Start Free

Revenue Share by Genre with Window Functions

advanced~10 min35 pts
📊 View Insights

Problem

The executive team wants to understand revenue distribution across music genres. For each genre, calculate the total revenue, its percentage share of total revenue, and its rank.

Use window functions to compute the percentage and rank without subqueries.

Schema: Genre

ColumnType
GenreIdINTEGER (Primary Key)
NameTEXT

Schema: InvoiceLine

ColumnType
InvoiceLineIdINTEGER (Primary Key)
InvoiceIdINTEGER (Foreign Key)
TrackIdINTEGER (Foreign Key)
UnitPriceNUMERIC(10,2)
QuantityINTEGER

Requirements:

  • Join InvoiceLine → Track → Genre
  • Calculate GenreRevenue = SUM(UnitPrice * Quantity), rounded to 2
  • Calculate RevenuePercent using a window SUM over the total, rounded to 2
  • Calculate RevenueRank using RANK() ordered by revenue descending, then genre name ascending to break ties
  • Order by RevenueRank, limit to 10
Window FunctionsJOINAggregationRANKSUM
📊
📊 View Question Telemetry & Insights
Failure rate, silent bug autopsy & optimal query construction
Inspect →

Master SQL & Data Analytics

Ready to take your skills to the next level? Enroll in our comprehensive Data Analyst Career Track to master SQL, Python, Excel, and Power BI.

Explore the 12-Week Data Analyst Career Track

Related questions

  • Albums with Artist Namesintermediate
  • Tracks with Genre Namesintermediate
  • Customer Purchase Historyintermediate
  • Total Track Countbeginner
  • Track Count by Genreintermediate
  • Average Song Duration by Genreintermediate
  • Top 5 Countries by Salesbeginner
  • Most Prolific Artistsintermediate
SQL Editor

Run your code to see the result here.

Topfolio

Learn data analytics online. Real skills, real projects, real community.

courses

  • Career Tracks
  • Work Experience
  • Best Data Analyst Course in India
  • SQL Fundamentals
  • SQL Advanced
  • Python for Data
  • Micro Free Courses

practice

  • SQL Fundamentals Interview Test
  • SQL Advanced Coding Test
  • All Practice Tests

resources

  • How to Become a Data Analyst
  • SQL Interview Questions
  • Data Analyst Salary Guide
  • Free Datasets for Practice
  • SQL vs NoSQL Guide
  • Data Analyst vs Data Engineer vs Data Scientist

employers

  • Enterprise Screening
  • AI Proctoring Demo
  • Volume Pricing
  • Employer Portal

company

  • About
  • Terms
© 2026 Topfolio. All rights reserved.Made with ❤️ for aspiring analysts