title: Mysql query: count column
body: <p>Hi all guys i have a technical problem, i have a table with records like this:</p>
  
  <pre><code>DATE        SIP DURATION  TYPE
  2017-02-22  670    9      NO ANSWER
  2017-02-22  670    9      ANSWER
  2017-02-22  670    9      ANSWER
  2017-02-22  671    9      NO ANSWER
  </code></pre>
  
  <p>i'd like have result like this:</p>
  
  <pre><code>SIP   DURATION  NOANSWER  ANSWER
  670     18         1        2
  671     9          1        0
  </code></pre>
  
  <p>i'll make query like this:</p>
  
  <pre><code>select 
  DISTINCT(SIP),
  (select count(*) FROM table where TYPE="ANSWERED")
  (select count(*) FROM table where TYPE="NO ANSWERED")
  from table
  </code></pre>
  
  <p>but the result count all record on the table, is better use group by?</p>
  
  <p>sorry i'm noob :(
  thanks for the time
  Marco</p>