Data Interview Qs - Classifying animals in SQL

InterviewQs

Classifying animals in SQL

SQL Database Querying Window Function Subquery

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

Hi, 

Suppose you're given the following table showing the weights of various unique animals in a zoo:

Table: animal_weights

animal_ID weight_lbs zoo_ID
9992 1040 12
99929 1090 12
12993 2190 11
9821 750 11
96673 580 11
1411 690 12
1415 695 9
1410 690 9
1117 1000 9
1677 800 9
13457 600 9
389745 200 9
324589 950 9
7854320 1200 9
87345 1700 9
83248582 765 9

Using this table, write a SQL query to split the data into quartiles based animal weight (where 1 is the heaviest, 4 is the lightest). Then, within each quartile, rank the animal weights from heaviest to lightest in descending order.

Your output should be structured like this:

animal_id weight_lbs quartile rank_in_quartile
X X 1 1
X X 1 2
X X 1 3
X X 1 4
X X 2 1
X X 2 2
etc etc etc etc

Click here to view the table in an interactive SQL fiddle.


 

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

Key phrases

Older messages

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

Top online order locations by revenue

Wednesday, March 30, 2022

SQL, Database Querying, Window Function, Subquery, InterviewQs Top online order locations by revenue SQL Database Querying Window Function Subquery Forward this email to a friend or colleague and

Probability of sitting in the aisle based on the plane ticket's letter

Monday, March 28, 2022

Python, Probability, Data Structures, Pandas, Data Analysis, Data Visualization, InterviewQs Probability of sitting in the aisle based on the plane ticket's letter Python Probability Data

You Might Also Like

Some Tesla Supercharger jobs get a jolt

Tuesday, April 30, 2024

Plus: Amazon CodeWhisperer changes its name and Arc gets a Windows version View this email online in your browser By Christine Hall Tuesday, April 30, 2024 Welcome to TechCrunch PM, bringing you the

Relief From Tinnitus: Free Discovery Call!

Tuesday, April 30, 2024

Do you suffer from tinnitus or a ringing in your ears? 1 in 3 adults over the age of 65 will suffer from this condition and often don't know there are things you can do to help. Our friends at

WebAIM April 2024 Newsletter

Tuesday, April 30, 2024

WebAIM April 2024 Newsletter Read this newsletter online at https://webaim.org/newsletter/2024/april Feature Web Accessibility in the 2024 Presidential Campaigns WebAIM's John Northup ran the US

👀 Being More Productive on a Smaller Screen — How to Hide Games on Steam Family Sharing

Tuesday, April 30, 2024

Also: What to Expect From Apple's "Let Loose" Event, and More! How-To Geek Logo April 30, 2024 Did You Know The letter J is the only letter that makes no appearance on the Periodic Table.

PEP 686, Lazy Evaluation, Serverless Python, and More

Tuesday, April 30, 2024

PEP 686: Make UTF-8 Mode Default #627 – APRIL 30, 2024 VIEW IN BROWSER The PyCoder's Weekly Logo PEP 686: Make UTF-8 Mode Default This Python Enhancement Proposal outlines making UTF-8 the default

Daily Coding Problem: Problem #1427 [Easy]

Tuesday, April 30, 2024

Daily Coding Problem Good morning! Here's your coding interview problem for today. This problem was asked by Amazon. Given an array and a number k that's smaller than the length of the array,

🎙 My advice for film + TV creatives on the AI wave

Tuesday, April 30, 2024

Learning AI fast + Karate Kid references ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌

Ranked | The Top 20 Countries in Debt to China 💸

Tuesday, April 30, 2024

The 20 nations featured in this graphic each owe billions in debt to China, often posing concerns for their economic future. View Online | Subscribe Presented by Voronoi: The App Where Data Tells the

Noonification: RaspberryPi: Technology Overload - LAMP🕯 to UASP🐝

Tuesday, April 30, 2024

Top Tech Content sent at Noon! The first AI-powered startup unlocking the “billionaire economy” for your benefit How are you, @newsletterest1? 🪐 What's happening in tech this week: The

Issue #50: ScreenFloat by Matthias Gansrigler

Tuesday, April 30, 2024

Today, we're looking at ScreenFloat by Matthias Gansrigler. ScreenFloat is a screenshot management utility that lets you create floating screenshots so you can easily reference them no matter what