select distinct count(query_id) as total_query
--,QUERY_TEXT
--,DATABASE_NAME
--,SCHEMA_NAME
--,QUERY_TYPE
--,USER_NAME
--,ROLE_NAME
--,WAREHOUSE_NAME
--,WAREHOUSE_SIZE
,date_part(day, start_time) as "Day"
--,round(bytes_scanned/1024/1024/1000) as GB_scanned
,SUM(total_elapsed_time) / 60000/60 as TOTAL_elapsed_Hours
--,(partitions_scanned / nullif(partitions_total,0)) * 100 as pct_table_scan
--, percent_scanned_from_cache * 100 as pct_from_cache
--,bytes_spilled_to_local_storage as spill_to_local
--,bytes_spilled_to_remote_storage as spill_to_remote
from snowflake.account_usage.query_history
where --(bytes_spilled_to_local_storage > 1024 * 1024 or
-- bytes_spilled_to_remote_storage > 1024 * 1024 or
-- percentage_scanned_from_cache < 0.1)
--and elapsed_Minutes > 120
--and bytes_scanned > 1024 * 1024
WAREHOUSE_NAME like 'WAREHOUSENAME%'
and START_TIME >= current_date()-31
--group by START_TIME desc;
group by "Day"
order by "Day";
Comments