How to Filter Records with the Aggregate Function SUM in SQL

Use the SUM() function to filter records in SQL. This function takes a single argument, which is the column you want to sum the values of. For example, if you wanted to sum the values in the amount column of your database, you would use the following query:

SELECT SUM(amount) FROM table_name;

Examples

Let's look at a few examples of how this function can be used. Suppose you have a table called transactions with the following data:

transactions
amount
1
20
30
40

If you wanted to sum the values in this table, you would use the following query:

SELECT SUM(amount) FROM transactions;

This query would return the result 100, since the sum of the values in the table is 100.

Additional Info

The SUM() function is supported by most major databases, including MySQL, PostgreSQL, and SQL Server. However, the syntax may vary slightly depending on the database you are using. For more information, check out the documentation for your particular database. 🤓

Want to build your own LLM Apps with AirOps👇👇