title: Distinct values, sum values, then join result
body: <p>I have a table:</p>
  
  <pre><code>| s_id | s_date     | s_movie               | s_hour | s_price |
  |    1 | 2015-11-11 | The lord of the rings |  11:00 |       5 |
  |    2 | 2015-11-11 | The lord of the rings |  11:00 |       4 |
  |    3 | 2015-11-11 | The lord of the rings |  11:00 |       4 |
  |    4 | 2015-11-11 | Harry Potter          |  12:00 |       5 |
  |    5 | 2015-11-11 | Harry Potter          |  12:00 |      13 |
  |    6 | 2015-11-11 | Harry Potter          |  12:00 |      13 |
  |    7 | 2015-11-11 | Harry Potter          |  12:00 |       5 |
  </code></pre>
  
  <p>And result:</p>
  
  <pre><code>$result = mysql_query("
      SELECT *
       , count(s_price) as uniq_p 
       , SUM(s_price) as uniq_all 
      from table 
      group 
      by s_movie
       , s_price 
      order 
      by s_movie desc
  ");
  </code></pre>
  
  <p>HTML table display:</p>
  
  <pre><code>&lt;b&gt;Date  Movie  Price  Sum&lt;/b&gt;
  2015-11-11 The lord..   2 x 4   8
  2015-11-11 The lord..   1 x 5   5
  2015-11-11 Harry..  2 x 5   10
  2015-11-11 Harry..  2 x 13  26
  </code></pre>
  
  <p>How to join results like this?</p>
  
  <pre><code>&lt;b&gt;Date  Movie  Price_1 Price_2  Sum&lt;/b&gt;
  2015-11-11 The lord..   2 x 4 1 x 5  13
  2015-11-11 The Harry..2 x 5 2 x 13 36
  </code></pre>
  
  <p>Here is a msql example:
  <a href="http://sqlfiddle.com/#!2/2c0f4/2" rel="nofollow">http://sqlfiddle.com/#!2/2c0f4/2</a></p>
  
  <p>And PHP code:</p>
  
  <pre><code>&lt;table border="1" style="width:50%"&gt;
  &lt;thead&gt;
  &lt;tr&gt;
      &lt;td&gt;Date&lt;/td&gt;
      &lt;td&gt;Movie&lt;/td&gt;
      &lt;td&gt;Price&lt;/td&gt;
       &lt;td&gt;Sum&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
   &lt;?  while ($row = mysql_fetch_array($result)):?&gt;
  
    &lt;tr&gt;
      &lt;td&gt;&lt;?= $row["s_date"]; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?= $row["s_movie"]; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?= $row["uniq_p"]; ?&gt; x &lt;?= $row["s_price"]; ?&gt;&lt;/td&gt;
       &lt;td&gt;&lt;?= $row["uniq_all"]; ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
  
  
  &lt;? endwhile ?&gt;
  &lt;/table&gt;
  </code></pre>