title: SUM on a Column Group
body: <p>i have three tables with structure something like</p>
  
  <pre><code>tasktime - starttime,endtime,packagedetailid,packageid
  packagedetailid - packageid,productid, etc
  productime - productid and searchesperday
  </code></pre>
  
  <p>and the query i am using on these is as follows</p>
  
  <pre><code>SELECT CONVERT(varchar, t.StartTime, 111) AS 'Date'
  , SUM(DATEDIFF(second, t.StartTime, t.EndTime)) / 60 AS DailyMinutes
  , COUNT(DISTINCT p.PackageDetailID) AS OrderCount
  , LEFT(CAST(SUM(DATEDIFF(minute, t.StartTime, t.EndTime))
       / (COUNT(DISTINCT p.PackageDetailID) + 0.0000001) AS varchar), 4) AS PerOrder
  , LEFT(CAST((COUNT(DISTINCT p.PackageDetailID) * 100)
       / (e.SearchesPerDay + 0.00000001) AS varchar), 4) AS WeightedOrderCount
  FROM  ProductTime AS e INNER JOIN dbo.PackageDetails AS p
   WITH (NOLOCK) ON e.ProductID = p.ProductID INNER JOIN 
  TaskTime AS t WITH (NOLOCK) ON p.PackageDetailID = t.PackageDetailId
  WHERE(t.EndTime IS NOT NULL) 
  AND (DATEDIFF(hour, t.StartTime, t.EndTime) &lt; 1) 
  AND (DATEDIFF(second, t.StartTime, t.EndTime) &gt; 0) 
  AND (t.UserId = '12345') 
  AND (t.StartTime BETWEEN '1/1/2010'
  AND '9/13/2010')
  GROUP BY CONVERT(varchar, t.StartTime, 111), e.SearchesPerDay
  ORDER BY CONVERT(varchar, t.StartTime, 111)
  </code></pre>
  
  <p>The OUTPUT is: </p>
  
  <pre><code>**date         dailyminutes  ordercount  perorder  weightordercount**
  
  2010/01/04     104                26    4.03    43.30
  2010/01/04     10                  1    9.99     1.24
  2010/01/04     19                  8    2.37     8.88
  2010/01/04     22                 11    1.99    10.90
  2010/01/04     18                  5    3.59     2.77
  2010/01/05     49                 17    2.99    28.30
  2010/01/05     31                  5    6.39     5.55
  2010/01/05     26                  6    4.33     5.99
  2010/01/05      8                  4    1.99     3.33
  </code></pre>
  
  <p>But i want to SUM up the <code>"Weightordercount"</code> against the date so that the output is</p>
  
  <pre><code>**date            dailyminutes  ordercount  perorder  weightordercount**
  
  2010/01/04         173           51     21.97       67.09
  2010/01/05         114           32     15.70       43.17
  </code></pre>
  
  <p>i am not a sql expert and need your help if this can be achieved by a Single SQL command or through a Strored Procedure</p>
  
  <p>Thanks in advance</p>