title: How do I use array_agg with a condition?
body: <p>I have a table with a list of potential customers, their activity, and their sales representative. Every customer can have up to 1 sales rep. I've built a summary table where I aggregate the customer activity, and group it by the sales rep, and filter by the customer creation date. This is NOT a cohort (the <code>customers</code> do not all correspond to the <code>scheduled_flights</code>, but rather this is a snapshot of activity for a given period of time) It looks something like this: </p>
  
  <p><a href="https://i.stack.imgur.com/cUwHz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/cUwHz.png" alt="enter image description here"></a></p>
  
  <p>Now, in addition to the total number of customers, I'd also like to output an array of those actual customers. The <code>customers</code> field is currently calculated by performing <code>sum(is_customer) as customers</code> and then grouping by the sales rep. To build the array, I've tried to do <code>array_agg(customer_name)</code> which outputs the list of all customer names -- I just need the list of names who also satisfy the condition that <code>is_customer = 1</code>, but I can't use that as a where clause since it would filter out other activity, like scheduled and completed flights for customers that were not new.</p>