Recap - Pictures
Part of the Fundamentals section of Coddy's SQL journey — lesson 63 of 72.
Challenge
EasyAvailable tables and columns:
picture_characteristics:day_of_month,ink_liters,colors_numpicture_interests:day_of_month,num_people_interested
Pictures have all kinds of characteristics, such as the amount of ink (in liters), the number of colors, and the number of people who want to buy them.
We want to identify days where the artist used less resources (ink and colors) while still maintaining positive interest from people, while the artist should use less ink and less color to save costs. In this challenge, we would like to examine this hypothesis. Follow these steps:
- Calculate the day-over-day difference for:
- ink_liters (name this column
ink_diff) - colors_num (name this column
colors_diff)
- ink_liters (name this column
- Filter the results to show only days where:
- ink_diff is negative (showing a decrease in ink usage)
- colors_diff is negative (showing a decrease in colors used)
- num_people_interested is greater than zero (at least one person is interested in the picture — note that the data may contain days with zero interest)
- Create a ranking column (
day_rank) that:- Ranks days from
1toNbased onnum_people_interested - Higher number of interested people should get a lower rank (1 being the best)
- Ranks days from
- Return:
day_of_monthday_rank
Order the results by day_rank in ascending order
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() Function8Statistics
Built-In Aggregate Part 1Built-In Aggregate Part 2Grouping Part 1Grouping Part 2Subqueries Part 1Subqueries Part 2Recap - Total Gain ShopRecap - Scooter ShopRecap - Coffee Shop11Window Functions part 1
ROW_NUMBER functionORDER BY criterionPARTITION BY criterionPARTITION & ORDERLEAD & LAG FunctionsRecap - LEAD & LAGRecap - PicturesRecap - Boxes3Specific 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 columns