Problem Statement
What’s a portable way to group daily sales by date if your engine lacks DATE_TRUNC?
Explanation
Casting a timestamp to DATE groups all times on the same calendar day. It is widely supported across engines.
String formatting works but can introduce locale issues and sort quirks.
Code Solution
SolutionRead Only
SELECT CAST(sale_ts AS DATE) AS d, SUM(amount) FROM sales GROUP BY CAST(sale_ts AS DATE);
Practice Sets
This question appears in the following practice sets:
