QUERY in Google Sheets

Runs a query on a range with select, where, group by and order by, and returns the result as a table.

Syntax

QUERY(data, query, [headers])
data
The range to query. Its columns are called A, B, C… after the sheet letters.
query
The query as text in quotes, such as "select A, B where C > 100".
headers (optional)
The number of header rows in the data. Left out, Google Sheets guesses.

Examples

E1=QUERY(A1:C6,"select A, sum(C) group by A")
ABCDEF
1RegionRepAmountRegionsum Amount
2NorthAnn120North320
3SouthBo80South230
4NorthCy200West50
5WestDi50
6SouthEd150

In plain words: From the table in A1:C6, list each region in column A with the total of column C.

E1=QUERY(A1:C6,"select B where C > 100 order by C desc")
ABCDE
1RegionRepAmountRep
2NorthAnn120Cy
3SouthBo80Ed
4NorthCy200Ann
5WestDi50
6SouthEd150

Practice QUERY

Related functions