gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 16:52:26 25 4
gpt4 key购买 nike

我有这个 SQL 语句:

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

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

enter image description here

Of course the result of the subquery is a small value : enter image description here

出了什么问题?

最佳答案

您需要使用子查询:

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;

关于mysql - 在 SQL 语句中使用局部变量时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52746262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com