【问题标题】:Convert MySQL code to Access SQL将 MySQL 代码转换为 Access SQL
【发布时间】:2013-12-30 05:23:12
【问题描述】:

我需要一些帮助,因为我是 Access 的新手。

我正在尝试建立一个高尔夫差点数据库并计算我必须为每个高尔夫球手拉出最后几轮比赛的差点。

我发现以下代码似乎可以完成我所追求的工作,但它是为 MySQL 而不是 Access 2013 编写的。(我已更改字段和表以匹配我将使用的表)

set @num := 0, @id := 0;

select PlayerID, RoundID, DatePlayed
from (
   select PlayerID, RoundID, DatePlayed,
      @num := if(@id = PlayerID, @num + 1, 1) as row_number,
      @type := type as dummy
  from IncludedRounds
  order by PlayerID, DatePlayed
) as x where x.row_number <= 2;

任何帮助都将不胜感激,因为我对 Access 和 VBA 的学习曲线很陡峭,而且我的目标已经完成了一半。

【问题讨论】:

  • 您是如何运行 Access SQL 的?这是.accdb 文件中存储的查询/视图,还是存储在 VBA 函数中的 SQL 字符串?

标签: mysql ms-access-2013


【解决方案1】:

一种方法(为每个玩家获得最后两轮

SELECT PlayerID, RoundID, DatePlayed
  FROM IncludedRounds t
 WHERE DatePlayed IN
(
  SELECT TOP 2 DatePlayed 
    FROM IncludedRounds
   WHERE PlayerID = t.PlayerID 
   ORDER BY DatePlayed DESC, RoundID DESC
)
 ORDER BY PlayerID, DatePlayed DESC, RoundID DESC;

这是 SQLFiddle 演示 它适用于 SQL Server,但它应该可以在 MS Access 中正常工作

【讨论】:

  • 谢谢,我会试一试的。
  • 刚刚尝试将 2 修改为 20,再次非常感谢。
猜你喜欢
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-15
  • 2010-10-22
相关资源
最近更新 更多