Please find below the query.How should I modify the query to include a group by clause on "groupby NDC"
select a.PatName as Patient,a.DrugLabelName as medication,a.dispenseDt as DispensedDate, a.daysSupply, a.PatID, a.NDC, a.RxNo,
from (select * from Rx..HRxs union all select * from FwArchive..HRxs)
left join HRxDirections as d on a.PatID = d.PatID and a.FacID = d.FacID and a.RxNo = d.RxNo and a.RoNo = d.RoNo and a.Posted =d.Posted
left outer join Pat..Patients as b on a.PatID = b.PatID and a.FacID = b.FacID
left outer join Fac..NursingStations as c on b.NsID = c.NsID and a.FacID = c.FacID
where a.FacId = '74' and a.DispenseDt >= '07/01/2012' and a.DispenseDt <= '01/09/2013' and a.PatId = '22'
and TransType in ('P', 'R', 'U', 'Q', 'B') order by a.DrugLabelName,a.DispenseDt