사용자가받는 퀴즈 목록과 옳은 질문 수, 퀴즈 카테고리, 점수 및 퀴즈 ID를 추적하는 테이블이 있습니다.
콜드 퓨전에는 각 퀴즈를 통과하는 cfloop가 있으며 즉석에서 각 퀴즈의 평균 점수, 최대 점수, 낮은 점수를 계산하여 표시합니다. 로드하는 데 시간이 오래 걸립니다. cfloop를 최적화 할 수있는 방법이 있습니까?
원래 쿼리는 다음과 같습니다.
SELECT Quizname,
NULLIF(QuizId, '') as QuizId,
NULLIF(InstructorId, '') as InstructorId,
NULLIF(Location, '') as Location,
cast(replace(quiz_user_quiz_percentage,'%','') as decimal(5,2)) as percentage
FROM QuizResults
where 0=0
and year(cast(datecompleted as date))>= 2019
그런 다음 Cfloop는이 쿼리를 통해 각 퀴즈 이름, 퀴 지드를 필터링하고 다음과 같은 평균, 최대 및 최소 점수를 얻습니다.
<cfloop query="getEachQuiz" >
<cfquery name="getStats" dbtype="query">
SELECT
count(percentage) as countScore,
max(percentage) as maxScore,
min(percentage) as minScore,
avg(percentage) as avgScore
FROM data
where Quizname= <cfqueryparam value="#getEachQuiz.Quizname#" cfsqltype="cf_sql_varchar" >
and QuizId= <cfqueryparam value="#getEachQuiz.QuizId#" cfsqltype="cf_sql_varchar" >
<cfif len(getEachQuiz.InstructorId) gt 0>
and InstructorId= <cfqueryparam value="#getEachQuiz.InstructorId#" cfsqltype="cf_sql_varchar" >
</cfif>
<cfif len(getEachQuiz.Location) gt 0>
and Location= <cfqueryparam value="#getEachQuiz.Location#" cfsqltype="cf_sql_varchar" >
</cfif>
</cfquery>
<tr>
<td>#getEachQuiz.Quizname#</td>
<td>#getEachQuiz.QuizId#</td>
<td>#getStats.countScore#</td>
<td>#numberformat(getStats.avgScore,'99.99')#%</td>
<td>#getStats.maxScore#%</td>
<td>#getStats.minScore#%</td>
</tr>
</cfloop>
루프 내에서 여러 CF 쿼리 쿼리를 실행하고 있습니다. 이것을 하나로 대체 할 수 있어야합니다.
<cfquery name="getStats" dbtype="query">
select quizname, quizid,instructorId, location
, count(percentage) as countScore
, min(percentage) as minScore
, max(percentage) as maxScore
, avg(percentage) as avgScore
from data
group by quizname, quizid,instructorId, location
</cfquery>
또한 기본 쿼리에서
where 0=0
and year(cast(datecompleted as date))>= 2019
와
where datecompleted >= '2019-01-01'
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다