2

我有一个问题,我正在使用 Ben Nadel 的 QueryAppend.cfc 加入来自两个不同数据源的两个记录集。我得到的数据是正确的,但数据的顺序不是预期的。组合结果集的排序方式如下,所有结果都以小写字母开头,附加到记录集的底部:

cfdump 的屏幕截图

我期待(并且需要)以下类型的排序:

苹果

艺术

瓶子

男生

硬币

代码如下:

<!---Calling Template--->

<cfquery name="getDataSet1" datasource="datasource1">
SELECT param1
FROM table1
</cfquery> 

<cfquery name="getDataset2" datasource="datasource2">
 SELECT param1
FROM table2
</cfquery> 

<cfscript>
// Create object
 TheUnionObject = createObject("component", "cfc/QueryAppend");
 // Call the function
myUnionResult = TheUnionObject.QueryAppend(getDataSet1, getDataSet2);
</cfscript> 

<!---Dump results--->
<cfdump var="#myUnionResult#">






 <!---QueryAppend.cfc--->
 <cfcomponent>
 <cffunction name="QueryAppend" access="public" returntype="query" 
 output="false"
 hint="This takes two queries and appends the second one to the first one. 
  Returns the resultant third query.">
 <cfargument name="QueryOne" type="query" required="true" />
 <cfargument name="QueryTwo" type="query" required="true" />
 <cfset var LOCAL = StructNew() />
 <cfquery name="LOCAL.NewQuery" dbtype="query">
       (
            SELECT
               *
            FROM
                ARGUMENTS.QueryOne
        )
    UNION 
        (
            SELECT
                *
            FROM
                ARGUMENTS.QueryTwo
        )  ORDER BY Param1 ASC
  </cfquery>
 <cfreturn LOCAL.NewQuery />
  </cffunction>
  </cfcomponent>

我假设这个默认的排序行为是一些底层的 ColdFusion 代码。谁能告诉我如何改变这个默认的 ORDER BY 行为?

4

1 回答 1

4

一个快速的解决方法是在您的 select 语句中添加一个字段,将您想要排序的字段值大写( upper ),然后按该字段排序,但仍输出未大小写的字段。类似于以下内容:

select   *, 
         upper(name) as upperName
from     query
order by upperName 
于 2018-12-14T15:43:46.110 回答