title: Is there a way to conditionally set the value of an aggregate in Oracle 12c?
body: <p>I'm looking to setup a query that would populate a column from a GROUP BY query based on whether the field has a specify value in the grouping. I'm working in Oracle 12c.</p>
  
  <p>Sample Table:</p>
  
  <pre><code>uname    event   tstamp
  ------  ------  ----------------------
  user1   3       10-SEP-19 11.00.00 AM
  user1   9       14-SEP-19 11.00.00 AM
  user1   32       14-AUG-19 11.00.00 AM
  user1   21      20-AUG-19 11.00.00 AM
  user1   8       23-AUG-19 11.00.00 AM
  user2   9       14-AUG-19 11.00.00 AM
  user2   8       23-AUG-19 11.00.00 AM
  user2   3       05-SEP-19 11.00.00 AM
  user3   15      06-AUG-19 11.00.00 AM
  user3   1       30-AUG-19 11.00.00 AM
  user3   7       14-SEP-19 11.00.00 AM
  </code></pre>
  
  <p>I would like the query to output: </p>
  
  <pre><code>uname    event   tstamp
  ------  ------  ---------------------
  user1   21      14-SEP-19 11.00.00 AM
  user2   8       05-SEP-19 11.00.00 AM
  user3   7       14-SEP-19 11.00.00 AM
  </code></pre>
  
  <p>I was looking for a query that worked something like this:</p>
  
  <pre><code>select uname, SomeAggregate(if contains 21 then 21 else DoesNotMatter) event, max(tstamp)
  from table
  group by uname
  </code></pre>