Recap - With Queries
Part of the Fundamentals section of Coddy's SQL journey — lesson 50 of 72.
Challenge
EasyAvailable tables and columns:
<b>devices_specs</b>:<b>device_id</b>,<b>width</b>,<b>height</b>,<b>num_features</b>,<b>opinion</b><b>devices_score</b>:<b>device_id</b>,<b>score</b>
A device's quality is measured by (width/height)*num_features.
We want to find all of the overrated devices. Fetch all of the devices where the device's opinion is greater than the average quality and the device's score is less than the average quality. Return only the device_id.
To solve it, use the WITH clause to create a subquery that calculates the average quality and reuse it in the main query.
Try it yourself
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns9Multiple tables
Basic Join Part 1Basic Join Part 2Recap - JoinSelf joinRecap - Self JoinUnionSimplify queries, WITH keywordRecap - With QueriesRecap - Real Estate Contractor