Use a small controlled dataset with known expected results. Validate each join/aggregation step separately using COUNT()/SUM(). Tool: https://www.db-fiddle.com Tips & sample queries → Search @PythonCodeWithYogendra SQL Testing.
COUNT()
SUM()