Query guidelines and sample queries (2025)

Best practices for bulk data export queries

Always use aggregation functions

Data in the tables is not guaranteed to be consolidated by date, URL, site, or any combination of keys. Therefore you should always aggregate your fields (SUM, COUNT, and so on) to guarantee that your row values are consolidated. For example, a table might have several rows with the query "fat cats":

query date search_type impressions ...fat cats 10-10-2022 WEB 1000fat cats 10-10-2022 WEB 200fat cats 10-10-2022 IMAGE 5000

Searching simply for the query "fat cats", even for a specific date and search type, can result in multiple rows. So you should aggregate as follows to see the sum of your impressions:

/* BAD way to see most popular query: will get only 1 row per query */SELECT query, impressions FROM searchconsole.searchdata_site_impressionORDER BY 2 DESC LIMIT 1;Result:fat cats 5000/* RIGHT way to see the most popular query */SELECT query, SUM(impressions) FROM searchconsole.searchdata_url_impressionWHERE query != '' /* Filter out anonymized queries */GROUP BY query ORDER BY 2 DESC LIMIT 1;Result:fat cats 6200

Limit queries by date to save processing costs

Remember that when you run a query on BigQuery you will be charged for it, and your tables can become quite large. The tables exported are date-partitioned, which allows for efficient limiting of the input scan to only days of interest - for large sites this can translate into real savings in query cost.A good way to minimize query costs is to use a WHERE clause to limit the date range in the date partitioned table.

Filter out null query strings

Anonymized queries often make up the single most common query for a site. An anonymized query is reported as a zero-length string in the table. If you want to see the most popular query for specific criteria, you probably want to filter out zero-length query values from your SQL query.

Sample queries

Below are some sample queries to help you get up and running with the data.

Results by site

All web stats, by day (last two weeks)

SELECT data_date AS date, sum(impressions) AS impressions, sum(clicks) as clicks, sum(clicks) / sum(impressions) AS ctr, /* Added one below, because position is zero-based */ ((sum(sum_top_position) / sum(impressions)) + 1.0) AS avg_positionFROM searchconsole.searchdata_site_impressionWHERE search_type = 'WEB' AND data_date between DATE_SUB(CURRENT_DATE(), INTERVAL 14 day) and CURRENT_DATE()GROUP BY data_dateORDER BY date desc LIMIT 1000

Top USA mobile web queries by clicks (last two weeks)

SELECT query, device, sum(impressions) AS impressions, sum(clicks) AS clicks, sum(clicks) / sum(impressions) AS ctr, ((sum(sum_top_position) / sum(impressions)) + 1.0) AS avg_positionFROM searchconsole.searchdata_site_impressionWHERE search_type = 'WEB' AND country = 'usa' AND device = 'MOBILE' AND data_date between DATE_SUB(CURRENT_DATE(), INTERVAL 14 day) and CURRENT_DATE()GROUP BY 1,2ORDER BY clicksLIMIT 1000

Results by URL

Top Discover URLs by clicks (on a specific day)

SELECT url, sum(impressions), sum(clicks) FROM searchconsole.searchdata_url_impressionWHERE search_type = 'DISCOVER' AND data_date = DATE(2022, 02, 01)GROUP BY urlORDER BY 3LIMIT 1000

Total query+url stats for FAQ rich results (last two weeks)

SELECT url, query, sum(impressions) AS impressions, sum(clicks) AS clicks, sum(clicks) / sum(impressions) AS ctr, ((sum(sum_position) / sum(impressions)) + 1.0) AS avg_positionFROM searchconsole.searchdata_url_impressionWHERE search_type = 'WEB' AND is_tpf_faq = true AND data_date between DATE_SUB(CURRENT_DATE(), INTERVAL 14 day) and CURRENT_DATE()GROUP BY 1,2 ORDER BY clicksLIMIT 1000

All your traffic by URL (last two weeks)

SELECT url, search_type, sum(impressions) as impressions, sum(clicks) as clicksFROM searchconsole.searchdata_url_impressionWHERE data_date between DATE_SUB(CURRENT_DATE(), INTERVAL 14 day) and CURRENT_DATE()GROUP BY 1,2ORDER BY 3 descLIMIT 1000

Impressions for queries containing "your_brand" (last two weeks)

SELECT regexp_contains(query, 'your_brand') AS contains_brand, sum(impressions) AS impressions, sum(clicks) AS clicksFROM searchconsole.searchdata_url_impressionWHERE search_type = 'WEB' AND data_date between DATE_SUB(CURRENT_DATE(), INTERVAL 14 day) and CURRENT_DATE()GROUP BY 1ORDER BY 2 descLIMIT 1000

Was this helpful?

How can we improve it?

Query guidelines and sample queries (2025)

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Twana Towne Ret

Last Updated:

Views: 6297

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.