hibernate转义“:”字符

rryofs0p  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(359)

我在这里找到了一些帖子和答案。我试过了,结果都不好。我不想使用存储过程。
我正在用java中的hibernate和mysql。我的一些查询字符串是:

SET @rank = 0; 
SET @limit = 0.1; 
SELECT (@limit := ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
   SELECT IF((@rank := @rank + 1) <= @limit, true, false) AS 'popularity', p.id 
   FROM Pics AS p 
   ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;

有人说解决方法是 /*'*/:=/*'*/ 在查询(post)中,但对我不起作用:

SET @rank = 0; 
SET @limit = 0.1; 
SELECT (@limit /*'*/:=/*'*/ ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
   SELECT IF((@rank /*'*/:=/*'*/ @rank + 1) <= @limit, true, false) AS 'popularity', p.id 
   FROM Pics AS p 
   ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;

我绝望了!
有什么想法吗?我会非常感激的!
谢谢!

rjzwgtxy

rjzwgtxy1#

最后,我可以在java查询代码中使用双反斜杠来修复它:

SET @rank = 0; 
SET @limit = 0.1; 
SELECT (@limit \\:= ROUND(COUNT(id) * @limit)) FROM Pics;
SELECT Q1.popularity FROM Pics AS p INNER JOIN (
   SELECT IF((@rank \\:= @rank + 1) <= @limit, true, false) AS 'popularity', p.id 
   FROM Pics AS p 
   ORDER BY p.points DESC
) AS Q1 ON Q1.id = p.id WHERE p.id = 7;

相关问题