我有一个表的输出,如果不满足某些要求,我想突出显示该表。我可以让它在一个部分上正常工作,但是当我在两个表的内部联接之后在QofQ上使用代码时,它将不起作用。
当转储变量时,我可以看到它们是正确的,而且我100%知道其中一家公司没有负数,因此应该正确显示,但是两家公司都显示为红色。
我显然看不到任何东西,或者QofQ是否有导致这种情况的限制?
我还在学习,所以请客气:)
查询:
<cfquery name="suppNeg" datasource="users">
SELECT companies.subID, companies.companyID, companies.suppName
, suppresult_old.companyID, suppresult_old.O18, suppresult_old.O19
, suppresult_old.O20, suppresult_old.O22, suppresult_old.WDPVC1
, suppresult_old.WDPVC2, quarterID
FROM suppresult_old INNER JOIN companies
ON suppresult_old.companyID=companies.companyID
WHERE quarterID = 8
AND companies.subID = #session.auth.companyID#
ORDER BY companies.suppName ASC
</cfquery>
<cfquery dbtype="query" name="subs">
SELECT DISTINCT suppName, companyID, subID
FROM suppNeg
ORDER BY suppName ASC
</cfquery>
<cfquery name="columntotals" datasource="users">
SELECT O18,O19,O20,O22, WDPVC1, WDPVC2
FROM suppresult_old INNER JOIN companies
ON suppresult_old.companyID=companies.companyID
WHERE quarterID = 8
AND companies.subID = #session.auth.companyID#
</cfquery>
<cfset O18Value = valueList(columntotals.O18) />
<cfset O18total = listToArray(O18Value) />
<cfset O19Value = valueList(columntotals.O19) />
<cfset O19total = listToArray(O19Value) />
<cfset O20Value = valueList(columntotals.O20) />
<cfset O20total = listToArray(O20Value) />
<cfset O22Value = valueList(columntotals.O22) />
<cfset O22total = listToArray(O22Value) />
<cfset WDPVC1Value = valueList(columntotals.WDPVC1) />
<cfset WDPVC1total = listToArray(WDPVC1Value) />
<cfset WDPVC2Value = valueList(columntotals.WDPVC2) />
<cfset WDPVC2total = listToArray(WDPVC2Value) />
<cfquery name="suppliers" datasource="users">
SELECT suppName, companyID, subID
FROM companies
WHERE subID=#session.auth.companyID#
ORDER BY suppName ASC
</cfquery>
输出:
<cfoutput query="subs">
<div class="container" width="1100">
<div class="row">
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfif (arraysum(O18total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong></a>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(O19total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(O20total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(O22total)) lt 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(WDPVC1total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<a href="2tierReport.cfm?quarterID=8&companyID=#companyID#">
<cfelseif (arraysum(WDPVC2total)) LT 0>
<div class ="col-sm-4 supphighlight1">
<h4>
<span class="glyphicon glyphicon-exclamation-sign" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
<cfelse>
<a href="suppReports_admin.cfm?quarterID=8&companyID=#companyID#">
<div class ="col-sm-4 supphighlight">
<h4>
<span class="glyphicon glyphicon-ok-circle" style="color:##ffffff; font-size: 32px; vertical-align: middle;" aria-hidden="true"></span><strong> #subs.suppName#</strong>
</h4>
</div>
</a>
....
答案 0 :(得分:1)
要消化的东西很多,没有任何数据样本,但是我要:一息:)我认为问题在于代码正在比较苹果和桔子。 “子”查询包含单个公司和subId的详细信息。 (我不知道实际数据是什么样子,因此下面的示例仅用于说明)
但是,cfif
比较可以计算所有公司和subId的总数。因此,如果O20的总数(O18等)为负,则cfoutput中的每个公司都为负。
如果只需要合计(按companyId和subId),则在SQL中计算起来要容易得多。使用SQL聚合函数SUM()代替所有ValueList()
,ArraySum()
和QoQ。我不知道您使用的是哪个DBMS,但是类似的东西应该可以在大多数数据库中使用:
注意:我“猜测” QuarterID是suppresult_old表中的一列
<!--- NOT TESTED --->
<cfquery name="totalsByCompany" datasource="users">
SELECT companies.subID
, companies.companyID
, companies.suppName
, suppresult_old.quarterID
, SUM(suppresult_old.O18) AS O18Total
, SUM(suppresult_old.O19) AS O19Total
, SUM(suppresult_old.O20) AS O20Total
, SUM(suppresult_old.O22) AS O22Total
, SUM(suppresult_old.WDPVC1) AS WDPVC1Total
, SUM(suppresult_old.WDPVC2) AS WDPVC2Total
FROM suppresult_old
INNER JOIN companies ON suppresult_old.companyID=companies.companyID
WHERE suppresult_old.quarterID = 8
AND companies.subID= <cfqueryparam value="#session.auth.companyID#" cfsqltype="cf_sql_integer">
GROUP BY companies.subID
, companies.companyID
, companies.suppName
, suppresult_old.quarterID
ORDER BY companies.suppName ASC
</cfquery>
然后在cfoutput中,使用计算得出的SUM:
<cfoutput query="totalsByCompany">
....
<cfif O18total LT 0> .... code here
<cfelseif O19total LT 0>.... code here
<cfelse> ...
</cfif>
</cfoutput>
在旁边:如果您是S.O.的新手,可能会想念How to create a Minimal, Complete, and Verifiable example。将(尽可能最小的)独立的示例放在一起演示该问题,可以使很多人更轻松地解决问题,并且问题closed的范围太广了:)另外,https://trycf.com之类的工具和https://sqlfiddle.com非常适合共享可运行的示例。