title: Select the MYSQL5.7 series that matches the condition from the result of the SELECT clause
body: <h3>what I want to do</h3>
  <p>In MYSQL5.7 series, I want to SELECT the items that meet the conditions from the result of the SELECT clause, but I can not select.</p>
  <h3>The code I created</h3>
  <pre class="lang-sql prettyprint-override"><code>select
     b_id
     , created_at
     , (select count(*)+1 
       from a
       where b_id = x.b_id and created_at &gt; x.created_at
    ) as n
  from a as x
  order by x.b_id, x.created_at desc
  ;
  </code></pre>
  <h3>results of this code</h3>
  <p>Running the above code produces the following result. I would like to modify the above code to count the number n=1 for the following result, but I am not sure how.</p>
  <pre><code>b_id        created_at            n
  1           20/07/18 22:47  1   
  2           20/03/24 06:08  1       
  5           20/08/30 19:25  1   
  6           20/08/29 14:53  2   
  6           20/08/27 00:00  3
  </code></pre>
  <h3>What I tried</h3>
  <p>I thought it would be possible to get it by enclosing the select clause in a subquery as follows and counting the select results with a condition, but I could not.</p>
  <pre class="lang-sql prettyprint-override"><code>select
    count(y.n = 1)
  from(
    select
     b_id
     , created_at
     , (select count(*)+1 
       from a
       where b_id = x.b_id and created_at &gt; x.created_at
     ) as n
    from a as x
    order by x.b_id, x.created_at desc
  ) as y;
  </code></pre>