educative.io

Explanation missing for question 4's answer

Why is the correct answer 5 10 15? Isn’t we just… summing the only integer in the SUM() or it is done differently? We don’t use any column name in SELECT, how are the values in table used there?

Thank you!


Course: https://www.educative.io/collection/5352985413550080/6335716377231360
Lesson: https://www.educative.io/collection/page/5352985413550080/6335716377231360/4565491877150720

Hey @Dmitry_Polovinkin!

I hope you’re doing great. There is a table given in the question and we need to tell what the query outputs. The table has only one column “Number” as follows:

Number
1
2
3
4
5

And following is the query:

SELECT SUM(1) FROM tableA;
SELECT SUM(2) FROM tableA;
SELECT SUM(3) FROM tableA;

We usually use the name of the column with the SUM() function. But if we specify a number in the function. It returns the number of rows if 1 is specified. In the case of 2, it will multiply the number of rows by 2. The number of rows is multiplied by 3 if we have specified 3 in the SUM() function. And the query given in the question will output 5, 10, and 15 using this logic.

I hope this explanation helps. Also, thank you for pointing this out. We are working on reviewing this course and we will soon fix the gaps in this course.

Happy learning!

1 Like

oh, that’s really interesting, didn’t know about that! Thanks! :slight_smile: