我正在尝试在VBA中为生成计算排名字段的ADODB.Recordset对象编写SQL查询。使用transact-SQL不起作用,如此处的示例所示。
strSQL = "SELECT DISTINCT [MONTH-YYYY], Location, (SUM([O/T Earnings])/SUM([Monthly Earnings])) AS OT_AS_PCT "
strSQL = strSQL & "RANK() OVER (PARTITION BY [MONTH-YYYY] ORDER BY (SUM([O/T Earnings])/SUM([Monthly Earnings])) DESC) AS RANK "
strSQL = strSQL & "FROM [Overtime Data$] "
strSQL = strSQL & "GROUP BY [MONTH-YYYY], Location "
rst_ranks.Open strSQL, cnn, adOpenStatic, adLockReadOnly
我注意到在使用ADODB中的函数之前,SQL函数不起作用,并且必须在它们的位置使用VBA函数。是否有允许PARTITION BY参数的VBA Rank()函数。
谢谢!
答案 0 :(得分:0)
答案 1 :(得分:0)