US · interviewqs.com

Number of pairs in SQL

SQL, Database Querying, Subquery,


This email was sent

Is this your brand on Milled? Claim it.

InterviewQs

Number of pairs in SQL

SQL Database Querying Subquery

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

Hi, 

Suppose you're given the following table showing sock inventory. Each row represents an individual sock (with the same style/size), and the 'color' column denotes the sock's color. Given this information, write a SQL query to return the number of pairs (two socks with matching colors) that can be made from the inventory shown. Your result should be returned as a single integer number.

Table: color_sorting

sock_id color
1 red
2 blue
3 black
4 blue
5 red
6 black
7 red
8 white
9 red
10 blue
11 red
12 red

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


 

You’ve accumulated 405 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
Are you sure?

Lists help you organize the brands that you care about. Your lists are private to you.