English 中文(简体)
使用无效值的查询列上的Arramin 矩阵
原标题:ArrayMin on query column with a null value
  • 时间:2012-05-24 19:50:48
  •  标签:
  • coldfusion

CF8

我正用这条线来获取查询列的 MIN 值。 我刚刚注意到一个记录栏中的无效值造成了错误。 是否有简单的方法可以让ArrayMin 跳过列以绕行, 并装入包含全部非null 值的数组?

<cfset temp_data_min = #round(ArrayMin(query_x["some_field"]))#>

谢谢!

最佳回答

您可以绕过您的数组, 创建一个新的数组, 新数组不包含任何空值。 然后对新数组应用 ArrayMin 函数 。

<cfset newArray = []>
<cfloop index="x" array="#query_x["some_field"]#">
  <cfif x NEQ  null >
      <cfset arrayAppend(newArray, x)>
  </cfif>
</cfloop>
<cfset temp_data_min = round(ArrayMin(newArray))>

未测试

问题回答

建立 Al 使用询问查询时所说的话, 只是在查询中添加 Min () 调用 。

<cfquery name="query_x_fixed" dbtype="query">
SELECT Min(some_field) as some_field
FROM query_x
WHERE some_field IS NOT NULL
</cfquery>

<cfset temp_data_min = round(query_x_fixed.some_field)>

测试在CF9工作

最简单的方法可能是只用那列进行查询,然后删除空格。

<cfquery name="query_x_fixed" dbtype="query">
SELECT some_field
FROM query_x
WHERE some_field IS NOT NULL
</cfquery>

<cfset temp_data_min= round(ArrayMin(query_x_fixed["some_field"]))>

(未经测试)

您可以将列转换为列表,然后转换为数组,将解决方案保留在一行。 ListToArray 默认忽略空列表项目,这是无效值的值。

<cfset temp_data_min = Round(ArrayMin(ListToArray(ValueList(query_x.some_field, Chr(7)), Chr(7))))>

这应比任何其他拟议解决办法更快,而且守则较少。

我已经指定了使用逗号作为数字小数分隔符的地方的分隔符。 如果您是在美国或者另一个使用“ ” 的地方, 您可以删除分隔符参数 。

使用的附加函数 :





相关问题
JQuery AJAX .load - flash chart doesnt load in IE

An IE issue has me completely stumped. I have a coldfusion page that uses JQuery s AJAX .load function to load in a new flash file that is generated by coldFusion s cfchart tag. This works completely ...

Best Coldfusion Library for OpenID [closed]

I am getting ready to start a project that requires using OpenID within Coldfusion 8. I have found a number of different options and was wondering what has worked the best, get s the most support, ...

Find ColdFusion Generated ID

Is there a way to find the elements generated by ColdFusion s <CFLayout> and <CFLayoutArea> tags? These tags: <cflayout type="tab" name="MyAccount"> <cflayoutarea name="...

ColdFusion COM error

I am upgrading from CF4.5 to CF8. Calls to COM dll s that used to work in version 4.5 now throw a "Complex object types cannot be converted to simple values.." error. The COM object has a few arrays ...

What s the best way to write engine-specific CFML code?

Sometimes it is necessary to write different code for Adobe ColdFusion vs Railo vs OpenBD, due to differences in implementation. Do people have a specific method that they use for this? For example, ...

热门标签