You are building a monthly revenue report in a PostgreSQL 15 database. The source table orders stores the precise purchase timestamp in the column order_created_at (TIMESTAMP). Before aggregating, you must transform every timestamp so that all rows from the same calendar month are grouped under the identical key (for example, 2025-03-15 and 2025-03-31 should both become 2025-03-01 00:00:00). Which single SQL expression will perform this normalization in one step so you can immediately use it in a GROUP BY clause?
DATE_TRUNC('month', order_created_at) returns a TIMESTAMP whose lesser time fields are set to their lowest values, meaning the day becomes 1 and the time becomes 00:00:00. Grouping by this expression therefore buckets every timestamp from the same calendar month under one identical value.
EXTRACT(month FROM order_created_at) returns only the numeric month (1-12); grouping by it would mistakenly merge data from the same month across different years. TO_CHAR(order_created_at,'YYYY-MM') formats the value as a string, not a timestamp, and does not reset the day or time. DATEDIFF('month', order_created_at, CURRENT_DATE) is not available in PostgreSQL and, even if it were, would yield an integer offset rather than a normalized date. Hence, DATE_TRUNC is the only option that meets the requirement.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the DATE_TRUNC function do in PostgreSQL?
Open an interactive chat with Bash
Why is EXTRACT not suitable for grouping timestamps by month?
Open an interactive chat with Bash
What is the difference between TO_CHAR and DATE_TRUNC?
Open an interactive chat with Bash
CompTIA Data+ DA0-002 (V2)
Data Analysis
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99 $11.99
$11.99/mo
Billed monthly, Cancel any time.
$19.99 after promotion ends
3 Month Pass
$44.99 $26.99
$8.99/mo
One time purchase of $26.99, Does not auto-renew.
$44.99 after promotion ends
Save $18!
MOST POPULAR
Annual Pass
$119.99 $71.99
$5.99/mo
One time purchase of $71.99, Does not auto-renew.
$119.99 after promotion ends
Save $48!
BEST DEAL
Lifetime Pass
$189.99 $113.99
One time purchase, Good for life.
Save $76!
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .