Recap - Real Estate Contractor
Part of the Fundamentals section of Coddy's SQL journey — lesson 51 of 72.
Challenge
MediumAvailable tables and columns:
<strong>real_estate</strong>:<strong>asset_id</strong>,<strong>value</strong>,<strong>date</strong><strong>potential</strong>:<strong>asset_id</strong>,<strong>forecast</strong>
Some analysts forecast what is going to be the growth for real estate assets. We want to check if their forecast is true.
For each asset in the real_estate table, calculate the ratio between the value of a newer date to the value of an older date.
For example, if there is an asset whose value in 2022-01-01 was 5 and in 2022-05-01 was 10 then that ratio is 10/5 = 2.
Ignore all of the comparisons that the day difference between the two dates is smaller than 101.
There are many dates for each asset so there are many ratios to compare. keep only the biggest ratio for each asset.
Finally, divide this ratio with the matching forecast from the potential table (call this field ratio_forecast) and sort the results in descending order.
The final result should have the asset_id and ratio_forecast.
Keep only the assets where the ratio_forecast is bigger than 1.
Note: To get a decimal solution from divide operation (/) you sometimes need to multiply the numerator by 1.0.
For example, instead of a / b use a * 1.0 / b to get the decimal result (when a and b are variables)
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