From 609a8d65d4be8ae0ff7465e87fa3cebd350e7041 Mon Sep 17 00:00:00 2001 From: FAQ Bot Date: Fri, 6 Feb 2026 19:46:09 +0000 Subject: [PATCH] NEW: How can I estimate the cost of executed queries in BigQuery within a spe --- ...326f6fa9_bigquery-cost-estimate-queries.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 _questions/machine-learning-zoomcamp/general/114_08326f6fa9_bigquery-cost-estimate-queries.md diff --git a/_questions/machine-learning-zoomcamp/general/114_08326f6fa9_bigquery-cost-estimate-queries.md b/_questions/machine-learning-zoomcamp/general/114_08326f6fa9_bigquery-cost-estimate-queries.md new file mode 100644 index 0000000..5ff9a85 --- /dev/null +++ b/_questions/machine-learning-zoomcamp/general/114_08326f6fa9_bigquery-cost-estimate-queries.md @@ -0,0 +1,27 @@ +--- +id: 08326f6fa9 +question: How can I estimate the cost of executed queries in BigQuery within a specific + time window, and identify which users ran them and when? +sort_order: 114 +--- + +Overview: +This snippet shows how to estimate the cost of executed queries in BigQuery over a time window using the INFORMATION_SCHEMA.JOBS_BY_PROJECT history metadata. The data is grouped by date, user, job_type, and statement_type to identify who ran queries and their cost. + +```sql +SELECT + DATE(creation_time) as date, + job_type, + statement_type, + user_email, + SUM(total_bytes_billed) / 1099511627776 * 6.25 as estimated_cost_usd, -- on-demand model costs are defined US$ 6.25 per TB + COUNT(*) as query_count +FROM `project-0c3c5223-416f-4242-b0f.region-us.INFORMATION_SCHEMA.JOBS_BY_PROJECT` +WHERE creation_time >= DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -60 DAY) --Interval can be modified +GROUP BY date, user_email, job_type, statement_type +ORDER BY estimated_cost_usd DESC -- Order by the highest cost execution based on total bytes billed +; +``` + +Output: +With this query we will be able to find insights about in which dates and what users did query executions with highest costs and optimize ones that are not efficient.