Google Sheets QUERY Function — Complete Guide with Examples 2027
Quick Summary
This comprehensive guide covers google sheets query function guide. Read on for practical tips, templates, and comparisons.
QUERY Basics
The QUERY function uses Google Visualization API Query Language — similar to SQL. Syntax: =QUERY(data, query, [headers]).
Example: =QUERY(A1:E100, "SELECT A, C, E WHERE B = 'Electronics' ORDER BY E DESC", 1) — selects columns A, C, E where category is Electronics, sorted by column E descending.
SELECT and WHERE
SELECT columns: =QUERY(data, "SELECT A, B, D") — choose specific columns to display.
WHERE filters: =QUERY(data, "SELECT * WHERE C > 1000 AND D = 'Paid'") — filter rows by conditions.
Date filtering: =QUERY(data, "SELECT * WHERE A >= date '2027-01-01' AND A <= date '2027-03-31'") — filter by date range.
GROUP BY and Aggregation
SUM by category: =QUERY(data, "SELECT B, SUM(E) GROUP BY B") — total sales per category.
COUNT: =QUERY(data, "SELECT B, COUNT(A) GROUP BY B") — count orders per category.
AVERAGE, MIN, MAX: =QUERY(data, "SELECT B, AVG(E), MIN(E), MAX(E) GROUP BY B LABEL AVG(E) 'Average', MIN(E) 'Min', MAX(E) 'Max'")
PIVOT Tables with QUERY
Create pivot tables: =QUERY(data, "SELECT A, SUM(E) PIVOT B") — rows are dates, columns are categories, values are sums.
QUERY is more flexible than Google Sheets built-in pivot tables. You can combine it with IMPORTRANGE to query data from other spreadsheets.
Advanced Techniques
Dynamic queries: use cell references in your query string with ampersand concatenation. Example: =QUERY(data, "SELECT * WHERE B = '" & F1 & "'") — filter changes when F1 changes.
Nested QUERY: use QUERY on the result of another QUERY for multi-step analysis.
QUERY + IMPORTRANGE: analyze data across multiple spreadsheets without manual copy-paste.
Try SheetStore Today
SheetStore offers affordable Google Sheets-based solutions for Vietnamese businesses. Starting from just 699,000 VND with lifetime access. View Pricing
Chia sẻ bài viết:
Tuân Hoang
Đội ngũ SheetStore
Bạn thấy bài viết hữu ích?
Đăng ký nhận thông báo khi có bài viết mới.