如何在 ColdFusion 7 中对查询对象进行排序?
我有一个查询对象,比方说返回了十五行。 出于所有意图和目的,我无法修改生成查询对象的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,查询的查询就是您执行此操作的方式。 您还可以通过其他方法来处理数据,但它们都很杂乱,而且不像 QoQ 那样简单。
QoQ(又名内存中查询)的功能之一是它可以用于任何返回查询对象的标签返回的查询,例如 CFDIRECTORY 和 CFPOP。
对于想知道如何执行查询的查询的人来说,这很简单:
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:
即使这个问题已经解决了,我想补充一点,您也可以使用底层的 Java 方法 sort(),它只需要一行,您不需要为此添加 UDF。 代码将如下所示:
需要调用 findColumn() 来获取排序列的索引,因为 sort() 处理的是列索引而不是列名称。 第二个参数指定排序顺序:TRUE = 升序,FALSE = 降序。
优点:一行调用,比 QoQ 更快
缺点:排序仅限于一列
底层 Java 类还有更多隐藏功能。 有关详细信息,请参阅以下链接:
在 Lucee 中(使用 4.5 和 5.2 进行测试),这也类似,甚至更简单:
希望,这给出了一些想法......
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:
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:
Hope, this gives some ideas...
请检查下一个网址
http://www.coldfusioncookbook。 com/entries/How-do-I-resort-a-query.html
Please check the next url
http://www.coldfusioncookbook.com/entries/How-do-I-resort-a-query.html