Skip to content

Commit ec44836

Browse files
Update cost-per-query-in-snowflake-using-credits_attributed_compute-metric-in-query_attribution_history-view.md
1 parent c956465 commit ec44836

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

cost-per-query-in-snowflake-using-credits_attributed_compute-metric-in-query_attribution_history-view.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ This View can be joined with `QUERY_HISTORY` View using [query_parameterized_has
1616
select
1717
query_parameterized_hash
1818
, query_history.warehouse_size
19-
, avg(credits_attributed_compute)
20-
, max(credits_attributed_compute)
21-
, min(credits_attributed_compute)
19+
, avg(credits_attributed_compute) as avg_credits_attributed_compute
20+
, max(credits_attributed_compute) as max_credits_attributed_compute
21+
, min(credits_attributed_compute) as min_credits_attributed_compute
2222
, count(*) as number_of_executions
2323
, left(any_value(query_history.query_text), 80) as query_text
2424
from SNOWFLAKE.ACCOUNT_USAGE.QUERY_ATTRIBUTION_HISTORY
2525
inner join SNOWFLAKE.ACCOUNT_USAGE.query_history using (query_parameterized_hash, start_time)
2626
group by all
27-
order by number_of_executions desc;
27+
having avg_credits_attributed_compute > 0
28+
order by number_of_executions * avg_credits_attributed_compute desc;
29+
order by credits_attributed_compute desc;
2830
```
2931

30-
|![carbon(12)](https://github.com/user-attachments/assets/1769d425-e546-4d5a-bda1-06242c06904a)|
32+
|![carbon(13)](https://github.com/user-attachments/assets/7a1a62fb-0736-4031-b532-c89f8b0e9f3c)|
3133
|:-:|
3234
|Using `query_parameterized_hash` to JOIN `QUERY_ATTRIBUTION_HISTORY` and `QUERY_HISTORY` to get an average of the Snowflake Credits consumed for recurrent queries |
3335

0 commit comments

Comments
 (0)