In depth analysis of the differences between SUM and COUNT in SQL statements

  • 2020-05-17 06:49:07
  • OfStack

SUM is the sum of the numeric columns of eligible records

COUNT is the number of qualified results (or records) in a query

Such as:

Table fruit

id name price

1 apple 3.00

2 pear 4.00

select count (price) from fruit; -- the result after execution is: 2 (indicating that there are 2 records)

select sum (price) from fruit; -- the result after execution is: 7:00 (indicating that the sum of the price fields of each record is 7.00)


Related articles: