Data Interview Qs - Sock sorting in SQL

InterviewQs

Sock sorting in SQL

SQL Database Querying Subquery Case Statement

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

Hi, 

You're given the following table showing the data output of a machine designed to determine a sock's color. You'll notice there can be multiple records per sock. Assuming there are only two possible colors for the socks (red and blue), write a SQL query to count the number of socks for each color such that any sock that has been flagged both red and blue by the machine is sorted into blue, any sock with just a blue flag is sorted into blue, and any sock with just a red flag is sorted into red.

Table: color_sorting

sock_id color
1 red
1 blue
1 blue
2 blue
3 red

You can view/query the data in an interactive SQL fiddle here.


 

You’ve accumulated 353 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

Creating a quick data pipeline

Friday, September 30, 2022

Python, Pandas, Data Pipeline, Chaining Functions, Data Processing, InterviewQs Creating a quick data pipeline Python Pandas Data Pipeline Chaining Functions Data Processing Forward this email to a

Roman numeral to integer

Wednesday, September 28, 2022

Python, Algorithims, Data Structures, Arrays, InterviewQs Roman numeral to integer Python Algorithims Data Structures Arrays Forward this email to a friend or colleague and challenge them to solve it.

Probability density functions and gas prices

Monday, September 26, 2022

Probability, Probability Density Function, Statistics, InterviewQs Probability density functions and gas prices Probability Probability Density Function Statistics Forward this email to a friend or

Top keywords and advertisers

Friday, September 23, 2022

SQL, Database Querying, Window Function, Subquery, Self-Join, InterviewQs Top keywords and advertisers SQL Database Querying Window Function Subquery Self-Join Forward this email to a friend or

Survival time of heart patients

Wednesday, September 21, 2022

Python, Pandas, Data Visualization, Probability Distribution, Goodness of Fit, Maximum Likelihood Estimate, InterviewQs Survival time of heart patients Python Pandas Data Visualization Probability

You Might Also Like

📧 What's inside MMA and how it can help you

Friday, April 26, 2024

What's Inside Modular Monolith Architecture? Hey there! 👋 I wish you an excellent end to the week. What better way to spend the weekend than diving headfirst into a 12+ hour course? Well, maybe

Data Science Weekly - Issue 544

Friday, April 26, 2024

Curated news, articles and jobs related to Data Science, AI, & Machine Learning ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

Develop highly relevant search applications using AI

Friday, April 26, 2024

New Elasticsearch and AI training ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ elastic | Search. Observe. Protect A world of AI possibilities door-test 2.png Explore

Stripe makes more changes

Thursday, April 25, 2024

TikTok is in trouble, and net neutrality is back View this email online in your browser By Christine Hall Thursday, April 25, 2024 Welcome back to TechCrunch PM, your home for all things startups,

💎 Issue 414 - From a Lorry Driver to Ruby on Rails Developer at 38

Thursday, April 25, 2024

This week's Awesome Ruby Newsletter Read this email on the Web The Awesome Ruby Newsletter Issue » 414 Release Date Apr 25, 2024 Your weekly report of the most popular Ruby news, articles and

💻 Issue 414 - JavaScript Features That Most Developers Don’t Know

Thursday, April 25, 2024

This week's Awesome Node.js Weekly Read this email on the Web The Awesome Node.js Weekly Issue » 414 Release Date Apr 25, 2024 Your weekly report of the most popular Node.js news, articles and

💻 Issue 407 - The Performance Impact of C++'s `final` Keyword

Thursday, April 25, 2024

This week's Awesome .NET Weekly Read this email on the Web The Awesome .NET Weekly Issue » 407 Release Date Apr 25, 2024 Your weekly report of the most popular .NET news, articles and projects

💻 Issue 414 - Everyone Has JavaScript, Right?

Thursday, April 25, 2024

This week's Awesome JavaScript Weekly Read this email on the Web The Awesome JavaScript Weekly Issue » 414 Release Date Apr 25, 2024 Your weekly report of the most popular JavaScript news, articles

📱 Issue 408 - All web browsers on iOS are just Safari with different design

Thursday, April 25, 2024

This week's Awesome iOS Weekly Read this email on the Web The Awesome iOS Weekly Issue » 408 Release Date Apr 25, 2024 Your weekly report of the most popular iOS news, articles and projects Popular

💧 Don't Bother Liquid Cooling Your AMD CPU — Why You Should Keep Using Live Photos on iPhone

Thursday, April 25, 2024

Also: We review the Unistellar Odyssey iPhone Telescope, and More! How-To Geek Logo April 25, 2024 Did You Know Charles Darwin and Abraham Lincoln were both born on the same day: February 12, 1809. 💻