title: How to get summation with count larger than certain amount
body: <p>I want to have a sql that gives recipient that received of amount >= 1024, with number of transfer &lt;=3.</p>
  
  <p>e.g.,</p>
  
  <p><a href="https://i.stack.imgur.com/DTDC1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DTDC1.png" alt="enter image description here"></a></p>
  
  <p>The result is:</p>
  
  <p><a href="https://i.stack.imgur.com/QlUV5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QlUV5.png" alt="enter image description here"></a></p>
  
  <p>Johnson is listed since 
  Johnson account is listed because it has received 1112 USD in the following three transfers: 512 USD + 100 USD + 500 USD, Taylor is with 1 transfer of USD 1024. Williams is not there since he receives 1200 in four transactions.</p>
  
  <p>I try</p>
  
  <pre><code>Select recipient as account_name from transfers group by recipient 
  having sum(amount)&gt;=1024  and count(amount)&lt;=3
  </code></pre>
  
  <p>It doesn't work correctly.
  I am using PostgreSQL, SQLLites syntax is fine too.</p>
  
  <p>Attached is the table and row creation for your convenient</p>
  
  <pre><code> create table transfers (
        sender varchar(1000) not null,
        recipient varchar(1000) not null,
        date date not null,
        amount integer not null
    );
  
  insert into transfers values('Smith','Taylor',convert(date,'2002-09-27'),'1024')
  insert into transfers values('Smith','Johnson',convert(date,'2005-06-26'),'512')
  insert into transfers values('Williams','Johnson',convert(date,'2010-12-17'),'100')
  insert into transfers values('Williams','Johnson',convert(date,'2004-03-22'),'10')
  insert into transfers values('Brown','Johnson',convert(date,'2013-03-20'),'500')
  insert into transfers values('Johnson','Williams',convert(date,'2007-06-02'),'400')
  insert into transfers values('Johnson','Williams',convert(date,'2005-06-26'),'400')
  insert into transfers values('Johnson','Williams',convert(date,'2005-06-26'),'200')
  </code></pre>