title: balance stock in SQL SERVER
body: <p>I am having 2 tables where i am supposed to show in qty, out qty and balance qty of items in stock i wrote my query as below:    </p>
  
  <pre><code>SELECT I.Date as Date, 
  P.ResourceName as ItemName,
  P.ResourceRate as Rate,
  i.TotalInQty as InwardsQuantity,
  s.TotalOutQty as OutwardsQuantity,
  i.TotalInQty-S.TotalOutQty as Balance,
  O.UnitSymbol As ItemUnit
  FROM UnitMaster O
  INNER JOIN Resource_Master P
   ON O.UnitCode = P.Unitcode
  LEFT JOIN
  (
    select sum(i.Qty) TotalInQty, Nameofitem
    from Inwards_Master I
    group by Nameofitem
  ) I
  ON I.Nameofitem= P.ResourceName
  LEFT JOIN
  (
    select sum(s.qty) TotalOutQty, Nameofitem
    from Outwards_Master S 
    group by s.Nameofitem
  ) S
  ON I.Date=S.Date 
  AND I.Nameofitem =S.Nameofitem
  WHERE P.TenderCode=1
  </code></pre>
  
  <p>the above query is giving me an error like below:</p>
  
  <blockquote>
    <p>Msg 8120, Level 16, State 1, Line 14 Column 'Inwards_Master.Date' is
    invalid in the select list because it is not contained in either an
    aggregate function or the GROUP BY clause.</p>
  </blockquote>
  
  <p>can any 1 please help me out</p>