我正在运行以下两个语句:
首先是 A),它做了它需要做的事情并且可以工作:
SELECT
itemColumn
,valueColumn
,label
FROM
rstCombinedChartData
UNION ALL
SELECT
itemColumn
,CAST(valueColumn AS INTEGER) AS valueColumn
,label
FROM
rstChartData
这给了我以下结果:
接下来我需要获取这些结果并在这种情况下为每个值取回 itemcolumn 的总数是和否,即
i.e.
Yes 200
No 400
B)这是我必须实现的查询:
SELECT
itemColumn
,SUM(valueColumn) AS valueColumn
,label
FROM
rstCombinedChartData (this is above result set)
GROUP BY
label
,itemColumn
ORDER BY
label DESC
,itemColumn DESC
但是,我得到以下不正确的结果:
查询 B 发生了什么事,它应该是 yes = x 和 no = x,而不是我得到的是假的和所有的总数?
CF功能:
<cffunction name="getAverageChartData" hint="I return the data required to render an average chart." returntype="array" output="false">
<cfargument name="surveyList" hint="I am a record set of Surveys." required="true" type="query" />
<cfargument name="filter" hint="I am the optional filter which is to be applied to all results." required="false" default="" type="string" />
<cfset var local=structNew() />
<cfset var rstChartData="" />
<cfset var rstChartDataTotal="" />
<cfset var rstCombinedChartData=queryNew("itemColumn,valueColumn,label","varchar,integer,varchar") />
<cfset local.objQuestion=objQuestionService.get(arguments.surveyList.question_ID[1]) />
<cfset local.intQuestionTypeID = local.objQuestion.getTypeID() />
<cfset local.strSubQuestionList=local.objQuestion.getAnswer() />
<cfset local.strPossibleAnswerList=local.objQuestion.getPossibleAnswer() />
<cfset local.arrChartDataResult=arrayNew(1) />
<!--- loop over each school's survey --->
<cfloop query="arguments.surveyList">
<cfset local.arrChartData = getChartData(arguments.surveyList.survey_id, arguments.surveyList.question_id, arguments.filter) />
<!--- loop over each sub question and append (union) it to a running total --->
<cfloop array="#local.arrChartData#" index="rstChartData">
<cfquery name="rstCombinedChartData" dbtype="query">
SELECT
itemColumn
,valueColumn
,label
FROM
rstCombinedChartData
UNION ALL
SELECT
itemColumn
,CAST(valueColumn AS INTEGER) AS valueColumn
,label
FROM
rstChartData
</cfquery>
</cfloop>
</cfloop>
<!--- get the totals for each itemColumn --->
<cfquery name="rstChartDataTotal" dbtype="query">
SELECT
itemColumn
,SUM(valueColumn) AS valueColumn
,label
FROM
rstCombinedChartData
GROUP BY
label
,itemColumn
ORDER BY
label DESC
,itemColumn DESC
</cfquery>
好的 - 主要更新
我不知道为什么,但我错误地添加了这一行:
<cfset querySetCell(rstCombinedChartData, "itemColumn", "1") />
突然之间,查询开始在 Railo 中起作用!好的,现在我有一个额外的结果,“1”没有意义,但是 WTF!似乎Railo 不喜欢所有是的,没有答案我将其他东西放入混合中,它开始再次正确地踩它,就像它应该的varchars 一样。
有人知道这里发生了什么吗?我已经厌倦了将 sql 转换为 varchar 但这仅在 CF 级别不起作用,确实发生了一些事情。
如果我取出线路:
<cfset querySetCell(rstCombinedChartData, "itemColumn", "1") />
它可以追溯到: