Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

I have the following table in a Google Spreadsheet:

Name | Value
A    | 10
B    | 100
A    | 20
B    | 200
C    | 1000

How can I create another table based on a query:

select name, sum(value), count(value) from table group by name

so it looks like this:

Name | SUM   | COUNT
A    | 30    | 2
B    | 300   | 2
C    | 1000  | 1
share|improve this question

migrated from superuser.com Dec 1 '12 at 7:29

This question came from our site for computer enthusiasts and power users.

2 Answers 2

up vote 16 down vote accepted

By using the QUERY function you can achieve your goal:

=QUERY(Data!A1:B6;"select A, sum(B), count(B) group by A")

Using the other functions, makes it achievable as well:

=UNIQUE(Data!A2:A)
=SUM(FILTER(Data!B2:B;Data!A2:A=A2))
=COUNTA(FILTER(Data!B2:B;Data!A2:A=A2))

See example I've prepared: QUERY vs FUNCTIONS

share|improve this answer

You can use Pivot Tables to group data in Google Spreadsheets.

share|improve this answer
    
Why -1? Pivot Table definitely does it! googledocs.blogspot.com/2011/05/… –  Mehper C. Palavuzlar Dec 1 '12 at 10:50
    
Because the question was about doing it with SQL –  Jacob Jan Tuinstra Dec 1 '12 at 11:13
2  
He wants to create another table which he clearly defines in the question, and Pivot Table does create this table. This is a valid answer. –  Mehper C. Palavuzlar Dec 1 '12 at 13:37
    
@JacobJanTuinstra no he doesn't. –  spartacus Aug 6 at 7:42
    
Pivot Tables should probably be mentioned in the question comments section instead. It is definitely helpful and related, but not answer the question precisely - only because the question was specifically about a query and the QUERY function is the answer. –  Dave 11 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.