Arrayhard

QUERY()

Runs a Google Visualization API Query Language query across data.

Syntax
fx
=QUERY(data, query, [headers])
Example
fx
=QUERY(A1:D, "SELECT B, SUM(D) GROUP BY B")

Paste this into Google Sheets to run it. The live playground on this site covers 24 of the 61 functions, and QUERY isn't one of them yet.

Common pitfalls

  • Column references inside the query string use letters (SELECT A, B), even if your range starts mid-sheet.
  • Mixed types in a column (numbers stored as text) cause silent failures. Force types with Col1 + 0 or TO_TEXT().
  • The optional 3rd arg headers controls how many header rows to skip. Pass 1 if your range starts at row 1 with headers.
Related formulas
FILTER()
Returns a filtered version of the source range, returning only rows or columns which meet the conditions.
IMPORTRANGE()
Imports a range of cells from a specified spreadsheet.
Used by
ARRAYFORMULA()
Enables the display of values returned from an array formula into multiple rows/columns.
FILTER()
Returns a filtered version of the source range, returning only rows or columns which meet the conditions.
IMPORTRANGE()
Imports a range of cells from a specified spreadsheet.
SORT()
Sorts the rows of a range by values in one or more columns.