title: rank over in mysql
body: <p>I read <a href="http://onlamp.com/pub/a/mysql/2007/03/29/emulating-analytic-aka-ranking-functions-with-mysql.html" rel="nofollow noreferrer">this article</a>, and i have the code in oracle, but I want to convert it to work on MySQL.  In Oracle, i use the function rank, with four columns can eligible or not, how i can use this in mysql, or, it is not possible?</p>
  
  <p>This is the code, I want select the most eligible line, every line can have 4 columns completed, I want to rank one of which has more data.</p>
  
  <pre><code>SELECT vlr,
         data
  INTO   vn_vlr,
         vd_data
  FROM (SELECT a.*, rank() over (ORDER BY nvl(a.id_categoria, -1) DESC,
               nvl(a.id_peso, -1) DESC,
               nvl(a.id_faixa, -1) DESC,
               nvl(a.sexo, ' ') DESC ) rank
          FROM tab_regra_pagamento a
         WHERE a.id_competicao = pidcompedticao
           AND a.tipo = 'NORMAL'
           AND a.data_vencimento &gt; SYSDATE
           AND nvl(a.id_categoria, vid_categoria) = vid_categoria
           AND nvl(a.id_faixa, vid_faixa) = vid_faixa
           AND nvl(a.id_peso, vid_peso) = vid_peso
           AND nvl(a.sexo, vsexo) = vsexo)
  WHERE  rank = 1;
  </code></pre>