title: Counting number of statuses in group concat row
body: <p>I've taken over a project that is a real mess so I've left with bad code structure that is forcing me to basically program in <code>SQL</code>. So changing the way of calculating this is for now not an option.</p>
  
  <p>I have <code>$sqlAdd</code> variable that i need to populate in function and then concatenate that to main query to count number of lost tickets. </p>
  
  <p>Main query looks like this:</p>
  
  <pre><code>$sql = "SELECT COUNT(*) as num_tickets, SUM(t.total_amount) as total_payin, SUM(t.total_payout) as total_payout
  FROM t WHERE t.tickettime BETWEEN '$dateFrom' AND '$dateTo' AND t.bsid = $bsID
  $sqlAdd";
  </code></pre>
  
  <p>So $sqlAdd is getting from another function</p>
  
  <pre><code>$sqlAdd = getSqlAdd();
  </code></pre>
  
  <p>And in that function i have this:</p>
  
  <pre><code>$sqlAdd = " AND 'WON' NOT IN (
             SELECT GROUP_CONCAT(tr.ticketstatus)
             FROM tr INNER JOIN m ON tr.ticketid = m.ticketid
             WHERE tr.ticketid = t.ticketid GROUP BY m.ticket_groupid
             )
         AND 'PAYEDOUT' NOT IN (
             SELECT GROUP_CONCAT(tr.ticketstatus)
             FROM tr INNER JOIN m ON tr.ticketid = m.ticketid
             WHERE tr.ticketid = t.ticketid GROUP BY m.ticket_groupid
             )
         AND 'CLOSED' NOT IN (
             SELECT GROUP_CONCAT(tr.ticketstatus)
             FROM tr INNER JOIN m ON tr.ticketid = m.ticketid
             WHERE tr.ticketid = t.ticketid GROUP BY m.ticket_groupid
             )
         AND 'OPEN' NOT IN (
             SELECT GROUP_CONCAT(tr.ticketstatus)
             FROM tr INNER JOIN m ON tr.ticketid = m.ticketid
             WHERE tr.ticketid = t.ticketid GROUP BY m.ticket_groupid
             )";
  </code></pre>
  
  <p>GROUP_CONCAT(tr.ticketstatus) is getting me these rows when i execute it</p>
  
  <pre><code>CLOSED,CLOSED,CLOSED
  PAYEDOUT,PAYEDOUT
  CLOSED,CLOSED
  WON,LOST
  LOST,WON,WON,WON,WON,WON
  CLOSED,CLOSED
  LOST,LOST,WON
  WON,WON,WON,LOST,LOST,WON,WON
  LOST
  </code></pre>
  
  <p>I just want to count rows that have only LOST status in it. So the result should be 1. But i keep getting 7. It it counting every LOST status in results.</p>