将MySQL代码转换为Access SQL

时间:2013-12-30 05:23:12

标签: mysql ms-access-2013

我需要一些帮助,因为我是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的陡峭学习曲线,而且我已经达到了目标的一半。

1 个答案:

答案 0 :(得分:0)

一种方法(为每位玩家提供最后两轮

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中正常使用