在SQL语句中使用局部变量时出现问题

时间:2018-10-10 18:02:48

标签: mysql sql mysql-workbench local-variables

我有以下SQL语句:

<script type="text/javascript">
var websocketServerLocation = '{{urls['websockurl']}}'
</script>
<script type="text/javascript" src="/static/common/js/framework7.min.js"></script>
<script type="text/javascript" src="/static/common/js/reconnecting-websocket.min.js"></script>

我想限制列值返回的行。但是当我跑步时: It doesn't work

enter image description here

Of course the result of the subquery is a small valueenter image description here

怎么了?

1 个答案:

答案 0 :(得分:0)

您需要使用子查询:

SELECT * 
FROM (SELECT DNI, puntaje, @row := @row+1 as Puesto
      FROM postulante, (SELECT @row := 0) r
      WHERE idCa = 2 
        AND idPer = 1 
      ORDER BY puntaje DESC) sub
WHERE Puesto <= (SELECT vacantes 
                FROM carrera_abierta 
                WHERE idCa=2 AND idPer=1)
ORDER BY Puesto;