1. What’s a portable way to group daily sales by date if your engine lacks DATE_TRUNC?
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.
SELECT CAST(sale_ts AS DATE) AS d, SUM(amount) FROM sales GROUP BY CAST(sale_ts AS DATE);