title: using sql subtotals
body: <p>I have the following select statement:</p>
  
  <pre><code>SELECT 
   c.compname AS [Company]
  ,x.Ressnavn AS [Client]
  ,a.jobid AS [Job Number]
  ,a.JobNavn AS [Job Name]
  ,t.TName [Task Name]
  ,cu.DayDate AS [Booking Date]
  ,cu.HrsBooked AS [Scheduled Hours]
  ,tr.Sale AS [Sales Value]
  ,(cu.HrsBooked) * (tr.Sale) AS [Total] 
  
  
  FROM job a
  
      INNER JOIN jobplan jp on jp.JobId=a.jobid
      INNER JOIN JobDimensions AS z ON z.jobid = a.jobid
      INNER JOIN Ress AS x ON x.RessId = z.custid
      INNER JOIN JobPrice AS y ON y.JobId = a.Jobid
      INNER JOIN task t on t.PlanId = jp.PlanId
      INNER JOIN JobPriceactivity AS w ON w.priceId = y.priceId
      INNER JOIN taskres tr ON tr.TaskId = t.TaskId
      INNER JOIN emp e ON e.EmpId = tr.ResId
      INNER JOIN comp c ON e.compid = c.compid
      INNER JOIN CapUsed AS cu ON cu.RefId = tr.TaskResId AND cu.RefType=1 
      INNER JOIN arpaccount AS ar ON e.empname = ar.arpaccname
                                                              AND CAST (cu.DayDate AS DATE) BETWEEN @startdate AND @enddate
  
  WHERE c.compid = '107'  AND e.EMPID &gt;='2' AND cu.HrsBooked &gt; '0'
  
  GROUP BY
  x.Ressnavn 
  ,a.jobid  
  ,a.JobNavn  
  ,t.TName 
  ,cu.DayDate 
  ,cu.HrsBooked 
  ,y.priceid
  ,tr.Sale
  ,c.compname 
  </code></pre>
  
  <p>That gives me the following output but I would like to add in a subtotal of the column 'Total' at each change in client.  </p>
  
  <p>An example of what I would like to try and get to is highlighted in green on the output screen grab.</p>
  
  <p><a href="https://i.stack.imgur.com/KtLbs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KtLbs.png" alt="Output"></a></p>
  
  <p>Can anyone advise on the best way to do this?</p>