FAQ: Date, Number, and String Functions - Numbers II

This community-built FAQ covers the “Numbers II” exercise from the lesson “Date, Number, and String Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

SQL: Table Transformation

FAQs on the exercise Numbers II

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

https://www.codecademy.com/courses/sql-table-transformation/lessons/date-number-string-functions/exercises/numbers-ii?action=resume_content_item

For this problem, is the MAX or MIN times a combination of the cook_time and cool-down_time, or is it whichever one is highest or lowest? How come the MAX function gives a number of 5 for id 2, and for MIN function gives a number of 33 for id 2? What is this actually telling us here?

I got the answer correct, but do not understand what the result is actually telling us. Thanks

2 Likes

How can we find out MAX value from 2 tables added by UNION?
this doesn’t work:

SELECT MAX(SELECT cook_time FROM baked_goods
UNION
SELECT cool_down_time FROM baked_goods)
FROM baked_goods;

What you point out is correct. MAX should just give the highest value of the two and MIN the lowest. This is not the case when id=2 as you notice; also for id = 13 or id = 20 as we see at the results. I really cannot explain it, is seems so illogical!

I noticed something odd when looking again at the database scema in particular the structure of the baked_goods table.
The values of cook_time and cool_down_time are defined to take “text” format instead of “integer” as I would expect since we are dealing with numbers.
Maybe that is why the results we are commenting are unusual, because the code calculates MIN & MAX comparing not numbers but words/letters (strings).
So, I remembered from Python lessons , the concept of “lexicographical order”. I suppose this is related to all the above I mention.
I hope, someone more expert , would confirm that or give us his/her own explanation for the unusual results.

I finally had to just look at the solution because I was getting fed up with what should be an easy section. The official solution is not correct because the time fields for bake_time and cool_down_time are text and not integers and are being compared by lexicographic order.

This entire section feels very poorly designed and tested compared to most of the rest of the SQL content. This is a big reason why I’m on the fence about a paid codecademy subscription, I don’t really want to subscribe if the content quality varies this widely.

Hi,

Using this code, we can find the MAX or MIN of the two input columns:

SELECT id, MAX(cook_time, cool_down_time)
FROM baked_goods
GROUP BY 1
ORDER BY 1
LIMIT 10;

Essentially it checks if SELECT cook_time or SELECT cool_down_time is higher. Is there a way to actually stipulate whether or not something is cook_time or cool_down_time? The code that the exercise uses essentially shoves it all into a same column without noting from which column the value originally comes. I would say that that is the most vital information when making such a comparison.

Thanks,
-T