• For starters you'll need to include a GROUP BY on every column in the SELECT list that is not aggregated.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP