Skip to content

Commit 9f74d25

Browse files
Create cost-per-query-in-snowflake-using-credits_attributed_compute-in-query_attribution_history.md
1 parent fac42f0 commit 9f74d25

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Cost per Query in Snowflake using credits_attributed_compute in query_attribution_history
2+
3+
Snowflake has introduced a new View `QUERY_ATTRIBUTION_HISTORY` in `SNOWFLAKE.ACCOUNT_USAGE`. This View holds the Snowflake credits attributed to a Query execution in Snowflake.
4+
5+
```
6+
select credits_used_query_acceleration, credits_attributed_compute, query_parameterized_hash
7+
from SNOWFLAKE.ACCOUNT_USAGE.QUERY_ATTRIBUTION_HISTORY
8+
```
9+
10+
This VIEW can be joined with `QUERY_HISTORY` View using `query_parameterized_hash` as JOIN Key to get an average of the Snowflake Credits consumed for a given query.
11+
12+
```
13+
select
14+
query_parameterized_hash
15+
, avg(credits_attributed_compute)
16+
, max(credits_attributed_compute)
17+
, min(credits_attributed_compute)
18+
from SNOWFLAKE.ACCOUNT_USAGE.QUERY_ATTRIBUTION_HISTORY
19+
inner join SNOWFLAKE.ACCOUNT_USAGE.query_history using (query_parameterized_hash)
20+
group by all;
21+
```

0 commit comments

Comments
 (0)