【问题标题】:Need to change a MYSQL query using the @ as we updated our Mysql version需要使用 @ 更改 MYSQL 查询,因为我们更新了 Mysql 版本
【发布时间】:2019-06-11 22:15:20
【问题描述】:

我们将 Mysql 驱动程序更新为

数据库名称 MySQL 数据库版本 5.6.10-log 驱动名称 MySQL-AB JDBC 驱动

我们使用的是旧版本,但没有人知道那个版本是什么,因为那台机器已经死了。 下面的查询在我们的 railo 网站中运行。 MySQL 服务器不喜欢 @ 但我不知道如何重写,因为 MySQL 不是我的事,这是很多个月前编写的代码。

set @row = 0;

select nf.nid, @row:=@row+1 as ranking from financial nf 
where nf.year = (select distinct year from financial where type = 'Total income' Order by year DESC LIMIT 1) 
and nf.type in ('Total Spend','Total budget (Spend)') 
and nf.nid in (select ft_no from n where ft_type in (1)) 
and nf.value > 0 
order by nf.value desc

如果有人比我(大多数人)更了解 Mysql,请帮我解决这个问题。我相信您会在查询中发现更多问题,因此欢迎提供任何帮助。

提前致谢 安德烈亚

【问题讨论】:

  • “MySQL 服务器不喜欢@”是什么意思?有没有给出任何错误信息?
  • 是的,这是正确的,但错误并没有消失,但问题仍然存在。我正在尝试重建,但我的机器已重建
  • 这是错误。我们需要关闭一个功能。您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以获取正确的语法,以便在第 2 行 SQL 的“选择 nf.nid,@row:=@row+1 作为金融 nf where nf.yea”的排名附近使用我希望这会有所帮助

标签: mysql sql railo


【解决方案1】:

有时在单个查询中运行多个查询会出现问题。如果这是问题所在,您可以通过在查询中设置初始值来解决此问题:

select nf.nid, (@row := @row+1) as ranking
from financial nf cross join
     (select @row := 0) params
where nf.year = (select max(year)
                 from financial
                 where type = 'Total income'
                ) and
     nf.type in ('Total Spend', 'Total budget (Spend)') and
     nf.nid in (select ft_no from n where ft_type in (1)) and
     nf.value > 0 
order by nf.value desc;

我也简化了year 的子查询。

【讨论】:

  • 这解决了问题。非常感谢
猜你喜欢
  • 1970-01-01
  • 2012-06-29
  • 1970-01-01
  • 2014-03-02
  • 1970-01-01
  • 2016-05-03
  • 2011-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多