• Basically the same thing as Alan. I just wanted to note that it's considered best practice to post DDL and sample data in a consumable format, as well as expected results. You're new to this site so it's not a big deal that you didn't do it this time, but try to do it in future occasions.

    Note that we changed the way of calculating the dates to avoid using functions on columns and allow that indexes on that column can be used.

    CREATE TABLE scores(

    ID int,

    creationdate date,

    score int,

    MCC char(5))

    INSERT INTO scores VALUES

    (1, '2014-08-02', 30, '7422'),

    (1, '2014-08-05', 50, '7422'),

    (1, '2014-07-02', 20, '7422'),

    (1, '2014-07-01', 10, '7422')

    select MCC, sum(score) as total , sum(score) / t.tot , t.tot

    from scores ,

    (select CAST( SUM(score) AS decimal( 18,8)) tot

    from scores

    where creationdate BETWEEN DATEADD( day, DATEDIFF( day, 0, getdate()), -90) --SARGable argument (functions don't use columns)

    AND GETDATE()) t

    group by MCC, tot

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2