I have attached a spreadsheet which explains about output of this query and what we expect as output. We need unique NDC records order by Date Fill Desc and SUM(DaysSupply) based on NDC. I assume, it will be easy if an expert can view the output which i attached on the spreadsheet. Simple logic, i am missing the syntax part !!
convert(varchar(10),DateOfBirth,101) as DateOfBirth,
convert(varchar(10),DateFilled,101) As DateFilled,
1.0 * Coalesce(SUM(dayssupply), 0) AS SumDaysSupply
WHERE FirstName = 'ABC'
AND LastName = 'ABC'
AND DateOfBirth = '02/09/2035'
AND Datefilled >= DATEADD(DAY, -90, DATEDIFF(DAY, 0, GETDATE()))
Group by FirstName,LastName,DateOfBirth,
ORDER BY Datefilled DESC