title: Grouping results within SQL
body: <p>I was thinking about doing this in crystal, but am thinking about doing it another way now. This is the way I was thinking about doing it before.  <a href="https://stackoverflow.com/questions/18020128/count-by-group-in-crystal-reports">Count by group in crystal reports</a></p>
  
  <p>I am pulling by transactions and need a count of unique people, but in the report they want to show the count of individual people and then show their services below as shown in the image. What I'd like to do is somehow get a count of unique users that I could just throw in at the bottom. Crystal won't allow me to do a count by group and users will have duplicates in the format they want it displayed. I am hopping that I can group it in the code then just add it to the bottom of the report. I hope I'm getting across what I'm trying to accomplish. If I can somehow just add the total of unique users at the bottom of the report it will finish it for me. Thanks in advance.  </p>
  
  <p><img src="https://i.stack.imgur.com/DgFhQ.png" alt="enter image description here"></p>
  
  <pre><code>select 
  
  distinct p.patient_id,
  pa.fname as 'Patient',
  p.clinic_id,
  p.service_id,
  p.program_id,
  p.protocol_id,
  p.discharge_reason,
  p.date_discharged
  
  from patient_assignment p
  join patient pa
  on p.patient_id = pa.patient_id
  where p.program_id not in ('TEST', 'SA', 'INTAKE' ) and (p.date_discharged between '2013-01-01 00:00:00.000' and '2013-06-01 00:00:00.000')
  and p.patient_id not in ('00000004', '00001667', '00020354')
  </code></pre>