QUERY function

Runs a Google Visualization API Query Language query across data.

Sample Usage

QUERY(A2:E6,"select avg(A) pivot B")

QUERY(A2:E6,F2,FALSE)

Syntax

QUERY(data, query, [headers])

  • data - The range of cells to perform the query on.

    • Each column of data can only hold boolean, numeric (including date/time types) or string values.

    • In case of mixed data types in a single column, the majority data type determines the data type of the column for query purposes. Minority data types are considered null values.

  • query - The query to perform, written in the Google Visualization API Query Language .

  • headers - [OPTIONAL ]- The number of header rows at the top of data . If omitted or set to -1 , the value is guessed based on the content of data .

Examples

Make a copy

Note: Each example is in its own tab.

Sample data

Click to open document

Select & where

Returns rows that match the specified condition using Select and Where clauses.

  • QUERY can accept either "Col" notation or "A, B" notation.
Click to open document

Group by

Aggregates Salary values across rows using Select and Group by clauses.

Click to open document

Pivot

Transforms distinct values in columns into new columns.

Click to open document

Order by

Aggregates Dept values across rows and sorts by the maximum value of Salary .

Click to open document

Headers

Specifies the number of header rows in the input range, which enables transformation of multi-header rows range input to be transformed to a single row header input.

Click to open document
true
Visit the Learning Center

Using Google products, like Google Docs, at work or school? Try powerful tips, tutorials, and templates. Learn to work on Office files without installing Office, create dynamic project plans and team calendars, auto-organize your inbox, and more.

Search
Clear search
Close search
Google apps
Main menu
6479694423332247366
true
Search Help Center
true
true
true
true
true
35
false
false
false
false
Create a Mobile Website
View Site in Mobile | Classic
Share by: