CODE WORKSPACE

Most expensive queries

Return query_id, query_label, gb_scanned, and cost_rank for the three queries that scanned the most data.

Rank the runs by gb_scanned descending, then keep the top three.

Sample input

query_runsQuery history with bytes scanned per run.
query_idquery_labelgb_scanned
1daily_active_users12
2orders_export240
3revenue_by_country3
4event_funnel85
5late_event_audit6
6adhoc_select_star180

Expected output

Expected outputThe three heaviest queries by bytes scanned, with their cost rank.
query_idquery_labelgb_scannedcost_rank
2orders_export2401
6adhoc_select_star1802
4event_funnel853

Constraints

Use RANK() OVER (ORDER BY gb_scanned DESC) as cost_rank. Order by gb_scanned DESC, query_id ASC, and keep the top 3.

Expected skills

Ranking query history by cost and selecting optimization targets.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.