我有这个问题(是的很长,正在努力使其更好)
<cfquery datasource="Intranet" name="getHighestDeptAverage">
DECLARE @today DATETIME
SET @today = '2014-04-13'
;with CTE as(
Select d.csedept_name,d.csedept_id, Average = CASE WHEN d.csedept_question5 IS NULL
THEN (Select AVG(((cast(c.rating1 as Float)+ cast(c.rating2 as Float)+cast (c.rating3 as Float)+cast(c.rating4 as Float))/4))
From intranet.dbo.CSEReduxResponses c
Where c.employeedept = d.csedept_id
AND c.execoffice_status > 0
AND month(approveddate) = MONTH(@today))
ELSE (Select AVG(((cast(c.rating1 as Float)+ cast(c.rating2 as Float)+cast (c.rating3 as Float)+cast(c.rating4 as Float)+cast(c.rating5 as Float))/5))
From intranet.dbo.CSEReduxResponses c
Where c.employeedept = d.csedept_id
AND c.execoffice_status > 0
AND month(approveddate) = MONTH(@today))
END
from Intranet.dbo.CSEReduxDepts d
)
Select Top 2 Ranks = RANK() Over(Order By Average DESC),*
from CTE
</cfquery>
我想输出前两名, 这就是我在做的事情:
<cfoutput query="getMaxstars">
<cfif rnk eq 1>
<cfset average_rating_max = total_stars>
<cfset average_rating_dept = first_name>
<cfset average_rating_dept_last_name = last_name>
</cfif>
<cfif rnk eq 2>
<cfset average_rating_max_runnerup = total_stars>
<cfset average_rating_dept_runnerup = first_name>
<cfset average_rating_dept_runnerup_last_name = last_name>
</cfif>
</cfoutput>
<cfoutput query="getHighestDeptAverage">
<h3>Winner: Department- #highest_dept_name_average#</h3>
<h3>Average: #hihest_dept_average# </h3>
<h4>Runner-up: Department- #highest_dept_name_runnerup# </h4>
<h4> Average: #highest_dept_name_average_runnerup# </h4>
</cfoutput>
现在输出结果两次,我只想输出 一旦。我认为它应该工作,因为我有另一个查询,我也这样做 if和output所以我不确定为什么输出两次?
答案 0 :(得分:5)
如果我正在阅读你的问题和代码,我相信你会想要删除
query="getHighestDeptAverage"
来自您的第二个&lt; cfoutput&gt;。
您在此处未返回查询结果,但您有两个结果,因此是第二个输出。