• Waiting for the pros to offer their solution but this is my attempt:

    with cte AS (

    select quoteid, requestid, createdat,

    ISNULL((select top 1 datediff(dd, b.createdat, a.createdat)

    from quote as b

    WHERE a.requestid <= b.requestid

    and datediff(dd, b.createdat, a.createdat) > 30), 0) as datedifference

    from quote as a)

    select b.EmailAddress, a.createdAt, ROW_NUMBER() OVER (PARTITION BY a.requestid, a.datedifference order by datedifference)

    from cte as a

    inner join Request as b

    on a.requestid = b.requestid

    ---------------------------------------------------------

    It takes a minimal capacity for rational thought to see that the corporate 'free press' is a structurally irrational and biased, and extremely violent, system of elite propaganda.
    David Edwards - Media lens[/url]

    Society has varying and conflicting interests; what is called objectivity is the disguise of one of these interests - that of neutrality. But neutrality is a fiction in an unneutral world. There are victims, there are executioners, and there are bystanders... and the 'objectivity' of the bystander calls for inaction while other heads fall.
    Howard Zinn