6. Numbers II bugged?


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Hi all, this is the first time that I post for help on the forum, if there is anything inappropriate, please excuse me.


SELECT id, cook_time, cool_down_time
FROM baked_goods; 

we’ll get the query results as shown below:

But the results of

SELECT id, MAX(cook_time, cool_down_time)
FROM baked_goods;

shown as

which made me extremely confused, because I think the MAX and MIN functions are supposed to return the greatest and least value respectively.
In the row where id = 2, the 33 of cool_down_time is larger than the 5 of cook_time obviously, but why the result returns as 5? The same circumstance occur in the rows where id = 13 and 15.

Could anyone explain it for me, please?
Much appreciate!

<In this course, it often helps to include a screenshot of your whole web browser – that lets everyone see what you see. If you wish to include a screenshot, add it below this line.>

<If you wish to copy/paste in your code, you can use this next section. This will allow others to copy/paste your code for testing – something that they won’t be able to do with just a screenshot.>

Oh I have figured it out by myself.

It is because of the data type of the columns, which is TEXT.
By MAX clause, the TEXT strings in the cook_time column and cool_down_time column will be compared by their first character. As a TEXT character, β€˜5’ is larger than β€˜33’, because β€˜5’ is larger than β€˜3’. And by the way, E is larger than C due to its latter position in the alphabet.

But what if the data type is INT? Then the numbers will be compared mathematically, which means β€˜33’ will be returned in the row where id = 2.

1 Like

Thank you so much for pointing this out, as I had been confused by the results but had not been aware that the type was text. You would think they might want to point this out, as it is a very avluable lesson

lol, you’re welcome! I have never expected that someone would reply this post after such a long time.
Yes, indeed. I was astonished that no one had had mentioned it while I was searching for help on the forum. So I posted it and hoped it could help someone else.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.