如何在 ColdFusion 7 中对查询对象进行排序?

发布于 2024-07-29 00:51:10 字数 207 浏览 2 评论 0原文

我有一个查询对象,比方说返回了十五行。 出于所有意图和目的,我无法修改生成查询对象的 SQL,但我需要按列对此查询对象进行排序。 有没有办法在 ColdFusion 7 中执行此操作而无需借助外部库?

编辑:我应该添加:我已经对此查询对象运行了一个查询,并在该查询的查询中执行了一个 ORDER BY 子句。 还有另一种方法可以做到这一点吗?

I have a query object, with, say, fifteen rows returned. For all intents and purposes, I can't modify the SQL which generates the query object, but I need to sort this query object by column. Is there a way to do this in ColdFusion 7 without resorting to an external library?

Edit: I should add: I've run a query on this query object, and done an ORDER BY clause in this query of the query. Is there another way of doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽心 2024-08-05 00:51:10

不,查询的查询就是您执行此操作的方式。 您还可以通过其他方法来处理数据,但它们都很杂乱,而且不像 QoQ 那样简单。

QoQ(又名内存中查询)的功能之一是它可以用于任何返回查询对象的标签返回的查询,例如 CFDIRECTORY 和 CFPOP。

对于想知道如何执行查询的查询的人来说,这很简单:

<cfquery name="resortQuery" dbtype="query">
    SELECT *
    FROM myQueryFromSomewhereElse
    WHERE
        COLUMN_NAME=<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#myFilterValue#" />
    ORDER BY
        SOME_OTHER_COLUMN_NAME ASC
</cfquery>

No, a query of query is the way you would do this. There are other ways you could monkey around with the data, but they're all kludgey and wouldn't be as straightforward as QoQ.

One of the powers of QoQ (aka in-memory queries) is that it can be used on the query returned by any tag that returns a query object, for instance CFDIRECTORY and CFPOP.

For folks wondering how to do a Query of Query, it's simple:

<cfquery name="resortQuery" dbtype="query">
    SELECT *
    FROM myQueryFromSomewhereElse
    WHERE
        COLUMN_NAME=<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#myFilterValue#" />
    ORDER BY
        SOME_OTHER_COLUMN_NAME ASC
</cfquery>
老旧海报 2024-08-05 00:51:10

即使这个问题已经解决了,我想补充一点,您也可以使用底层的 Java 方法 sort(),它只需要一行,您不需要为此添加 UDF。 代码将如下所示:

<cfset qQuery.sort(qQuery.findColumn("nameOfSortColumn"), TRUE)>

需要调用 findColumn() 来获取排序列的索引,因为 sort() 处理的是列索引而不是列名称。 第二个参数指定排序顺序:TRUE = 升序,FALSE = 降序。

优点:一行调用,比 QoQ 更快

缺点:排序仅限于一列

底层 Java 类还有更多隐藏功能。 有关详细信息,请参阅以下链接:

在 Lucee 中(使用 4.5 和 5.2 进行测试),这也类似,甚至更简单:

<cfset qQuery.sort("nameOfSortColumn", "asc")>

希望,这给出了一些想法......

Even when this question is already solved I want to add, that you could also use the underlying Java method sort(), which is just needing one line and you don't need to add a UDF for this. The code would then look like this:

<cfset qQuery.sort(qQuery.findColumn("nameOfSortColumn"), TRUE)>

The findColumn() call is needed to get the index of the sort column, because sort() is working with the column indexes and not with the column names. The second parameter specifies the sort order: TRUE = ascending, FALSE = descending.

Advantages: one-line call, faster than QoQ

Disadvantage: sort restricted to one column

There are much more hidden features of the underlying Java class. See the following links for more information:

In Lucee (tested with 4.5 and 5.2) this also works similar, and even simpler:

<cfset qQuery.sort("nameOfSortColumn", "asc")>

Hope, this gives some ideas...

南冥有猫 2024-08-05 00:51:10

请检查下一个网址

http://www.coldfusioncookbook。 com/entries/How-do-I-resort-a-query.html

<cfquery name="original" datasource="foo" >
  select name, age, rank
  from people
  order by age asc
</cfquery>

<!--- Resort by name --->
<cfquery name="newQuery" dbtype="query">
  select name, age, rank
  from original
  order by name asc
</cfquery>

Please check the next url

http://www.coldfusioncookbook.com/entries/How-do-I-resort-a-query.html

<cfquery name="original" datasource="foo" >
  select name, age, rank
  from people
  order by age asc
</cfquery>

<!--- Resort by name --->
<cfquery name="newQuery" dbtype="query">
  select name, age, rank
  from original
  order by name asc
</cfquery>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文