title: Stuck with this query
body: <p>My database looks like this</p>
  
  <p><strong>DailyData</strong></p>
  
  <pre><code>rID int
  Stock varchar
  rDate date
  Shares int
  price float
  </code></pre>
  
  <p>What I am trying to do is get the data for two dates.</p>
  
  <p><strong>Sample data</strong></p>
  
  <pre><code>rID    stock    rDate        Shares    price
  11     Stock1   21/03/2016   15        1.22
  12     Stock2   21/03/2016   22        2.23
  13     Stock3   21/03/2016   17        3.32
  14     Stock4   21/03/2016   10        4.24
  15     Stock1   22/03/2016   15        1.25
  16     Stock2   22/03/2016   20        2.27
  17     Stock3   22/03/2016   17        3.32
  18     Stock1   23/03/2016   15        1.28
  19     Stock2   23/03/2016   20        2.20
  20     Stock3   23/03/2016   17        3.32
  21     Stock4   23/03/2016   10        4.24
  </code></pre>
  
  <p><strong>Expected output</strong></p>
  
  <pre><code>Stock       Shares-21    Shares-20
  Stock1      15           15
  Stock2      22           20
  Stock3      17           17
  Stock4      10           0
  </code></pre>
  
  <p>My query against a SQL Server CE database:</p>
  
  <pre><code>Select 
      DD1.Stock, sum(DD1.Shares) as Shares-21, sum(DD2.shares) as Shares-20
  from 
      DailyData DD1, DailyData DD2
  where 
      DD1.rDate = '21/03/2016' and DD2.rDate = '20/03/2016' 
      and DD1.Stock = DD2.Stock
  group by 
      DD1.Stock
  </code></pre>
  
  <p>I am getting 7 rows of data instead of 4.</p>
  
  <p>Please help with the query.</p>
  
  <p>*******************************  new modification *********************
  i followed as suggested but it seems not to work.  this is a actual sql script.</p>
  
  <pre><code>Select P.pName,DD.Stock, 
    sum(case DD.rDate when '03/21/2016' then DD.Shares  else 0 end) as Shares21, 
    sum(case DD.rDate when '03/20/2016' then DD.Shares else  0 end) as Shares20
  from dailyData DD, Portfolios P
  where DD.rDate = '03/21/2016' or DD.rDate = '03/20/2016'
    and DD.pID = P.pID
    and DD.pID=1
  group by P.pName,DD.stock
  order by P.pName,DD.Stock
  </code></pre>
  
  <p>now for pID=1 there are 23 records for 20-Mar and 21-Mar</p>
  
  <p>upon running this query, it returns way more than 23.  I am expecting 23 records only.</p>