Complete the code to query the total credits used in the current month.
SELECT SUM(credits_used) AS total_credits FROM snowflake.account_usage.warehouse_metering_history WHERE usage_date >= DATE_TRUNC('month', CURRENT_DATE) AND usage_date <= [1];
The CURRENT_DATE function returns the current date without time, which matches the date type of usage_date. This ensures the date range filter works correctly.
Complete the code to filter credit usage for a specific warehouse named 'COMPUTE_WH'.
SELECT usage_date, credits_used FROM snowflake.account_usage.warehouse_metering_history WHERE warehouse_name = [1];String literals in SQL must be enclosed in single quotes. Double quotes or backticks are not valid for string literals in Snowflake SQL.
Fix the error in the code to correctly calculate daily credit usage.
SELECT usage_date, SUM(credits_used) [1] daily_credits FROM snowflake.account_usage.warehouse_metering_history GROUP BY usage_date ORDER BY usage_date;The AS keyword is used to assign an alias to a column or expression in SQL.
Fill both blanks to create a query that shows credit usage per warehouse for the last 7 days.
SELECT warehouse_name, SUM(credits_used) [1] total_credits FROM snowflake.account_usage.warehouse_metering_history WHERE usage_date >= DATEADD(day, -7, [2]) GROUP BY warehouse_name ORDER BY total_credits DESC;
Use AS to alias the sum column as total_credits. Use CURRENT_DATE to get the current date for the date filter.
Fill all three blanks to create a query that lists warehouses with credit usage greater than 100 in the last 30 days.
SELECT warehouse_name, SUM(credits_used) [1] total_credits FROM snowflake.account_usage.warehouse_metering_history WHERE usage_date >= DATEADD(day, -30, [2]) GROUP BY warehouse_name HAVING total_credits [3] 100 ORDER BY total_credits DESC;
Alias the sum column with AS. Use CURRENT_DATE for the date filter. Use the greater than operator > to filter warehouses with credit usage above 100.