1

CF8

この行を使用して、クエリ列のMIN値を取得していました。レコードセットのnull値がエラーの原因であることに気づきました。列をループしてすべての非null値を含む配列をロードせずにnullをスキップするようにArrayMinに指示する簡単な方法はありますか?

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

ありがとう!

4

4 に答える 4

5

クエリにMin()呼び出しを追加するだけで、クエリのクエリを使用してAlが言ったことを基に構築します。

<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で動作することがテストされています

于 2012-05-24T21:18:13.283 に答える
1

最も簡単な方法は、おそらくその列だけでクエリのクエリを実行し、nullを削除することです。

<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"]))>

(未検証)

于 2012-05-24T20:01:11.053 に答える
1

配列をループして、null値を含まない新しい配列を作成できます。次に、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))>

未検証

于 2012-05-24T20:05:21.000 に答える
1

You can keep the solution at one line by converting the column to a list then into an array. ListToArray defaults to ignoring empty list items, which is what the null values will be.

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

This should be faster than any of the other proposed solutions and is less code.

I've specified the delimiter for locales that use the comma as the decimal separator in numbers. If you're in the US or another locale that uses the "." then you can remove the delimiter arguments.

Additional functions used:

于 2012-05-26T10:56:57.120 に答える