Query function in Google Sheets

Hello friends!! Today we’ll be learning about the “Query” function in Google sheets. Query is one of powerful function in Google sheets. Combining with other functions makes it super helpful for the analysis.

QUERY Function Syntax

=QUERY(data, query, [headers])
ClauseUsage
selectSelects which columns to return, and in what order. If omitted, all of the table’s columns are returned, in their default order.
whereReturns only rows that match a condition. If omitted, all rows are returned.
group byAggregates values across rows.
pivotTransforms distinct values in columns into new columns.
order bySorts rows by values in columns.
limitLimits the number of returned rows.
offsetSkips a given number of first rows.
labelSets column labels.
formatFormats the values in certain columns using given formatting patterns.
optionsSets additional options.
fromThe from clause has been eliminated from the language.

Select, Where and Limit Command

=QUERY(Data!A:E,"SELECT A,B,D WHERE B='Male' LIMIT 5",1)

Order by Command

=QUERY(Data!A:E,"SELECT A,B,C ORDER BY B DESC",1)

Group by Command

=QUERY(Data!A1:E31,"SELECT B, COUNT(B) GROUP BY B ",1)

Pivot Command

=QUERY(Data!A1:E31,"SELECT COUNT(C) PIVOT B ",1)

Query function with examples Google Sheet


Leave a Reply

Your email address will not be published. Required fields are marked *