Data Interview Qs - Allocating votes from pooled elections

InterviewQs

Allocating votes from pooled elections

SQL Database Querying Subquery

Forward this email to a friend or colleague and challenge them to solve it.

Hi, 

Suppose you're running a school election, and are looking to tally up the results. The election is structured as follows:

  • Groups of students are split into voting pools, each with unique IDs. The voting pools are assigned a number of votes to allocate based on how many students are in the given pool
  • A voting pool can vote multiple times, but if they do their votes will be split evenly amongst the candidates

The voting information is stored in two tables (shown below): 'election_data' and 'voter_pools':

  • election_data contains each voting pool's votes for the given candidates. You'll notice many pools voted for multiple candidates
  • voter_pools contains the number of votes allocated to each unique pool

Given this information, write a SQL query to return the winner of the election, along with their associated votes.

Table: election_data

voting_pool_id candidate
9992 Susan
9992 Jerry
12993 Susan
12993 Lisa
96673 Chris
9992 Chris
1411 Tom
1117 Tom
96673 Allen
96673 Lisa

Table: voter_pools

voting_pool_id num_votes
9992 65
12993 30
96673 70
1411 65
1117 75

Click here to view/query the tables in an interactive SQL fiddle.


 

You’ve accumulated 281 questions since joining our email list. Create a premium account to access detailed solutions to each problem (including this one) + our new Case studies.


Was this email forwarded to you? You can join our list here to receive questions

How did you like today's question?

15411 Boischatel, Montreal, QC, H9H1Y7, Canada
Don't want to get these emails anymore? We'll forgive you if you unsubscribe

Older messages

Estimating the confidence interval for the length of an angelfish

Monday, April 11, 2022

Statistics, Confidence Intervals, InterviewQs Estimating the confidence interval for the length of an angelfish Statistics Confidence Intervals Forward this email to a friend or colleague and challenge

Classifying animals in SQL

Friday, April 8, 2022

SQL, Database Querying, Window Function, Subquery, InterviewQs Classifying animals in SQL SQL Database Querying Window Function Subquery Forward this email to a friend or colleague and challenge them

Plotting New York Airbnb listings

Wednesday, April 6, 2022

Python, Arrays, Data Structures, Data Visualization, InterviewQs Plotting New York Airbnb listings Python Arrays Data Structures Data Visualization Forward this email to a friend or colleague and

Simulating and visualizing rolls of a die

Monday, April 4, 2022

Python, Arrays, Data Structures, Algorithms, Simulation, Data Visualization, InterviewQs Simulating and visualizing rolls of a die Python Arrays Data Structures Algorithms Simulation Data Visualization

A/B testing a new landing page

Friday, April 1, 2022

Python, Product Questions, Data Structures, Pandas, Data Analysis, Statistics, InterviewQs A/B testing a new landing page Python Product Questions Data Structures Pandas Data Analysis Statistics

You Might Also Like

Software Testing Weekly - Issue 217

Monday, April 29, 2024

How do you deal with conflicts in QA? ⚔️ View on the Web Archives ISSUE 217 April 29th 2024 COMMENT Welcome to the 217th issue! How do you deal with conflicts in QA? Ideally, you'd like to know how

📧 Did you watch the free MMA chapters? (1+ hours of content)

Monday, April 29, 2024

Did you watch the free MMA chapters? Hey there! 👋 I wish you a fantastic start to the week. Last week, I launched Modular Monolith Architecture. More than 300+ students are already deep into the MMA

WP Weekly 191 - Essentials - Duplicate in Core, White Label Kadence, Studio for Mac

Monday, April 29, 2024

Read on Website WP Weekly 191 / Essentials It seems many essential features are being covered in-house, be it the upcoming duplicate posts/pages feature in the WordPress core or the launch of Studio

SRE Weekly Issue #422

Monday, April 29, 2024

View on sreweekly.com A message from our sponsor, FireHydrant: FireHydrant is now AI-powered for faster, smarter incidents! Power up your incidents with auto-generated real-time summaries,

Quick question

Sunday, April 28, 2024

I want to learn how I can better serve you ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌

Kotlin Weekly #404 (NOT FOUND)

Sunday, April 28, 2024

ISSUE #404 28st of April 2024 Announcements Kotlin Multiplatform State of the Art Survey 2024 Help to shape and understand the Kotlin Multiplatform Ecosystem! It takes 4 minutes to fill this survey.

📲 Why Is It Called Bluetooth? — Check Out This AI Text to Song Generator

Sunday, April 28, 2024

Also: What to Know About Emulating Games on iPhone, and More! How-To Geek Logo April 28, 2024 📩 Get expert reviews, the hottest deals, how-to's, breaking news, and more delivered directly to your

Daily Coding Problem: Problem #1425 [Easy]

Sunday, April 28, 2024

Daily Coding Problem Good morning! Here's your coding interview problem for today. This problem was asked by Microsoft. Suppose an arithmetic expression is given as a binary tree. Each leaf is an

PD#571 Software Design Principles I Learned the Hard Way

Sunday, April 28, 2024

If there's two sources of truth, one is probably wrong. And yes, please repeat yourself. ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌

When Procrastination is Productive & Ghost integrating with ActivityPub

Sunday, April 28, 2024

Automattic, Texts, and Beeper join forces to build world's best inbox, Reflect launches its iOS app, how to start small rituals, and a lot more in this week's issue of Creativerly. Creativerly