nerdexam
Snowflake

SOL-C01 · Question #29

A Snowflake table 'ORDERS' contains a 'ORDER DATE' column of data type DATE. You need to write a query that returns the order count for each month in the year 2023. Which of the following SQL snippets

The correct answer is C. Option C. The actual SQL code for options A–E wasn't included in your message - only the labels are shown. Without the snippets, I can't explain why each specific distractor is wrong. That said, here's what makes an answer correct for this type of Snowflake question, which you can map to o

Querying and Performance

Question

A Snowflake table 'ORDERS' contains a 'ORDER DATE' column of data type DATE. You need to write a query that returns the order count for each month in the year 2023. Which of the following SQL snippets is MOST efficient and accurate for achieving this?

Exhibit

SOL-C01 question #29 exhibit

Options

  • AOption A
  • BOption B
  • COption C
  • DOption D
  • EOption E

How the community answered

(44 responses)
  • A
    18% (8)
  • B
    9% (4)
  • C
    64% (28)
  • D
    7% (3)
  • E
    2% (1)

Explanation

The actual SQL code for options A–E wasn't included in your message - only the labels are shown. Without the snippets, I can't explain why each specific distractor is wrong.

That said, here's what makes an answer correct for this type of Snowflake question, which you can map to option C yourself:

The correct approach groups by truncated month using DATE_TRUNC('MONTH', ORDER_DATE) and filters to 2023 with a WHERE clause, like:

SELECT DATE_TRUNC('MONTH', ORDER_DATE) AS order_month, COUNT(*) AS order_count
FROM ORDERS
WHERE YEAR(ORDER_DATE) = 2023
GROUP BY 1
ORDER BY 1;

Common distractor patterns and why they fail:

  • Using TO_CHAR(ORDER_DATE, 'YYYY-MM') - works but is less efficient; it converts to string, preventing partition pruning
  • Grouping by MONTH(ORDER_DATE) alone - collapses months across years (January 2022 and January 2023 merge)
  • Using DATEPART - SQL Server syntax, not valid Snowflake
  • Filtering with ORDER_DATE LIKE '2023%' - invalid on a DATE type column

Memory tip: In Snowflake, always prefer DATE_TRUNC over string-based date formatting when grouping by time periods - it keeps the column as a native DATE/TIMESTAMP, enabling micro-partition pruning and accurate sorting.

If you paste the actual A–E SQL snippets, I can give a precise per-option breakdown.

Topics

#Date Functions#GROUP BY#Query Optimization#Temporal Filtering

Community Discussion

No community discussion yet for this question.

Full SOL-C01 Practice