这是我在 cfquery 输出之前的“employeeRatings”表中使用的 RAW DATA 示例:
(showcasing employeeID:1128 for the month of May)
employeeID | Possible_Factor | Factor | ratingDate
=======================================================================
1128 | .1 | .1 | 5/25/2013 2:05:13 PM
1128 | .1 | .0 | 5/22/2013 9:30:43 AM
1128 | .2 | .1 | 5/17/2013 9:42:09 AM
1128 | .1 | .1 | 5/13/2013 8:07:15 AM
1128 | .1 | .0 | 5/10/2013 7:52:51 AM
1128 | .4 | .0 | 5/6/2013 12:41:12 PM
这是 cfquery(SQL 语句):
SELECT ROUND(100 * (SUM(Factor) / SUM(Possible_Factor)), 2) AS employeeRating, CONVERT(CHAR(4), ratingDate, 100) + CONVERT(CHAR(4), ratingDate, 120) AS month, employeeID, DATEADD(MONTH, DATEDIFF(MONTH, 0, ratingDate), 0) AS shortdate
FROM employeeRatings
GROUP BY CONVERT(CHAR(4), ratingDate, 100) + CONVERT(CHAR(4), ratingDate, 120), DATEADD(MONTH, DATEDIFF(MONTH, 0, ratingDate), 0), employeeID
ORDER BY employeeID, DATEADD(MONTH, DATEDIFF(MONTH, 0, ratingDate), 0) DESC
在 cfquery 之后,输出将如下所示:
employeeID | employeeRating | month | shortdate
=======================================================================
1128 | 30 | May 2013 | 5/1/2013 12:00:00 AM
1128 | 60 | April 2013 | 4/1/2013 12:00:00 AM
1128 | 90 | Jan 2013 | 1/1/2013 12:00:00 AM
7310000 | 95 | April 2013 | 4/1/2013 12:00:00 AM
7310000 | 85 | Mar 2013 | 3/1/2013 12:00:00 AM
7310000 | 75 | Feb 2013 | 2/1/2013 12:00:00 AM
7310000 | 55 | Jan 2013 | 1/1/2013 12:00:00 AM
444981 | 27 | Mar 2013 | 3/1/2013 12:00:00 AM
444981 | 77 | Jan 2013 | 1/1/2013 12:00:00 AM
444981 | 97 | Nov 2012 | 11/1/2012 12:00:00 AM
444981 | 37 | Sept 2012 | 9/1/2012 12:00:00 AM
444981 | 47 | Aug 2012 | 8/1/2012 12:00:00 AM
我需要一个员工并列出他们最后三个评级(如果月份为空,则跳过空月份并获得下个月的评级,以展示最后三个记录的评级)。这是一个动态 cfquery,列出了 200 多名员工。以下是所需的输出:
supplierID | LastRating | SecondLastRating | ThirdLastRating
======================================================================
1128 | 30 | 60 | 90
7310000 | 95 | 85 | 75
444981 | 27 | 77 | 97
我在 SQL Server 2000(兼容性 80)上使用 ColdFusion,但是我使用的 ColdFusion 版本不支持 cfloop 组属性。我想获取新的输出并将其放入一个新的查询中,以便它可以与另一个查询连接。一个解决方案 = 来自 FB 的星巴克礼物 ;) 谢谢大家的时间和考虑!!!!