SELECT SUM returns a row when there are no records

后端 未结 8 1050
囚心锁ツ
囚心锁ツ 2021-01-17 10:38

I\'m finding some problems with a query that returns the sum of a field from a table for all the records that meet certain conditions. I expected to receive a \"No records f

8条回答
  •  执念已碎
    2021-01-17 10:57

    The sum of zero numbers is equal to 0 (that's math). So it would be only natural for select sum(something) to return 0 if there are no records to sum, similarly to select count(*) that should return 0 if the count is 0 (no records satisfying the predicate). That's in an ideal world of course.

提交回复
热议问题