Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9788

Google SpreadSheets query: how to join "grouped by" cells in a list?

$
0
0

Suppose I have this table:

| Name   | Amount | Category || name_1 | 10     | A        || name_2 | 2      | B        || name_3 | 3      | B        || name_4 | 6      | C        |

Thanks to this answer, I know how to write a query that groups the rows by category, and gives me sum of Amount by category, like this:

=QUERY(A2:C5,"select C, sum(B) group by C order by sum(B)")

enter image description here

My question is: how do I add a third row to my query, such that it lists the Name of every row in that group (possibly, but not necessarily, comma-separated)?

In other words, I'd like the result to look like this:

|   | sum | items          || B | 5   | name_2, name_3 || C | 6   | name_1         || A | 10  | name_4         |

Viewing all articles
Browse latest Browse all 9788

Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>