title: SQLite: how to isolate WHERE clause to only one dataset in a SELECT statement?
body: <p>I have a database with dated entries of customers, type of customer. Some make a purchase, some don't. </p>
  
  <p>Table looks like this:</p>
  
  <pre><code>DATE|sessionID|customer_type|purchase value| 
  </code></pre>
  
  <p>I'm trying to create a table that computes what is the total amount of customers, total amount of customers that make a purchase, and to sort it by customer type and date (weekly). </p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>CREATE TABLE KPIs (
  
  'week' integer,
  
  'customer_type' integer,
  
  'customer_traffic' integer,
  
  'customer_that_purchased' integer
  );
  
  INSERT INTO KPIs (
  
  week, 
  
  customer_type, 
  
  customer_traffic, 
  
  customer_that_purchased)
  
  SELECT 
  
  week, 
  
  customer_type_var, 
  
  count(session_id), 
  
  count(purchase_value) 
  
  FROM data 
  
  WHERE purchase_value &lt;&gt; 0 
  
  GROUP BY week, traffic_type_var ;
  </code></pre>
  
  <p>The problem when I do this is that the WHERE clause applies to both counting total customers and customers having made a purchase, which is obviously incorrect (it should only apply to counting customers having made a purchase).</p>
  
  <p>How can I SELECT multiple data sets and have WHERE clauses only applying to some data sets and not others?</p>