SQL for report generation (test)