Google Sheets – How to Perform SQL JOIN and SUM Equivalent

google sheets

I have this table:

|    A    |  B  |
|---------|-----|
| grocery | $10 |
| clothes | $40 |
| grocery | $19 |

etc.

So I'd like to have a column with an aggregation of the categories like grocery and clothes with the total expenses, what in SQL would be a JOIN with the aggregate function SUM()

How can I achieve this?

Best Answer

This is what I think you're looking for:

Formula

=QUERY(DATA!B1:C3;"SELECT B, SUM(C) GROUP BY B label B 'Type', SUM(C) 'Sum'")

Explained

Column C is aggregated by column B through a summation. Labels are added. In this particular case, the usage of JOIN in an SQL statement isn't applicable, since the aggregation is done on one table.

Screenshots

Data:
data

Result
result

Example

I've created an example file for you: Sum Aggregate