google spreadsheet - Why do I have to also SELECT an aggregate column to be able to use GROUP BY, if the only SELECTed column is already in GROUP BY? -


in data used formula below, column c contains list of product titles (these not unique, , many blank); column q contains category each product, , column f contains product's sales. if possible, i'd avoid posting actual data (as belongs employer), can mock bogus rows in identical format if it's deemed necessary.

what want produce list of non-blank product titles in category highest aggregate sales, sorted in descending order, limited 25 entries.

the following formula seems me legitimate:

=query('raw data'!a:q, "select c q = 'foo' , c != '' group c order sum(f) desc limit 25", 1) 

but isn't. error "cannot_group_without_agg". i've found make work, need select sum(f) well, so:

=query('raw data'!a:q, "select c, sum(f) q = 'foo' , c != '' group c order sum(f) desc limit 25", 1) 

first of all, why this? documentation (found here) states "if use group clause, every column listed in select clause must either listed in group clause, or wrapped aggregation function." don't see how first formula doesn't obey criterion; every column in select (i.e. c) listed in group clause.

second of all, how can best modify formula (if can @ all) able select c? if i'm not doing wrong (doubtful, possible), there workaround this, or have deal it?

this question, , others it, don't answer question - understand if want select multiple columns, in second formula given above, need provide aggregation function it's clear how grouped. in case, though, there's 1 column - want (and it) grouped. missing here doesn't allow this?

the easiest solution wrap query formula around first one:

=query(query('raw data'!a:q, "select c, sum(f) q = 'foo' , c != '' group c order sum(f) desc limit 25", 1),"select col1")


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo