⊗pyPmDBSu 117 of 128 menu

Sum of field values ​​in SQL in Python

To find the sum of the values ​​of one field (column), you should apply the SUM function.

Let's find the sum of all values ​​of id:

query = "SELECT SUM(id) FROM users"

The result of the executed code:

{'SUM(id)': Decimal('21')}

Find the sum of all users' salaries.

Find the sum of all user ages.

Find the sum of salaries of users whose age is greater than or equal to 25.

enru