Coldfusion 中的查询排序

Query sort in coldfusion

我有一组来自 excel 文件的数据读取文件并将结果放入一个变量中以创建一个新的 excel 有什么问题我尝试

local.sheetData =queryNew("FirstName,LastName,Address,Email,Phone,DOB,Role");
        for(row in data){
            queryAddRow(local.sheetData);
         
            if(row["First Name"] != '' || row["Last Name"] != '' || row["Address"] != '' || row["Email"] != '' || row["Phone"] != '' || row["DOB"] != '' || row["Role"] != ''){
                if(row["First Name"] === '' || row["Last Name"] === '' || row["Address"] === '' || row["Email"] === '' || row["Phone"] === '' || row["DOB"] === '' || row["Role"] === ''){

                    local.endresult = arrayToList(local.nullMessage)
                    querySetCell(local.sheetData, "FirstName", row["First Name"]);
                    querySetCell(local.sheetData, "LastName", row["Last Name"]);
                    querySetCell(local.sheetData, "Address", row["Address"]);
                    querySetCell(local.sheetData, "Email", row["Email"]);
                    querySetCell(local.sheetData, "Phone", row["Phone"]);
                    querySetCell(local.sheetData, "DOB", row["DOB"]);
                    querySetCell(local.sheetData, "Role", row["Role"]);
                   
                }else{
                    querySetCell(local.sheetData, "FirstName", row["First Name"]);
                    querySetCell(local.sheetData, "LastName", row["Last Name"]);
                    querySetCell(local.sheetData, "Address", row["Address"]);
                    querySetCell(local.sheetData, "Email", row["Email"]);
                    querySetCell(local.sheetData, "Phone", row["Phone"]);
                    querySetCell(local.sheetData, "DOB", row["DOB"]);
                    querySetCell(local.sheetData, "Role", row["Role"]);
                    
                }
            } 
        }
        
       return local.sheetData; 

它工作正常并得到类似

的结果

我想对这个查询进行排序,并显示第一个显示的行的任何单元格为空。如何在 coldfusion 中对查询进行排序?

在 ColdFusion 中对查询进行排序的最简单方法是使用 Query-of-Queries 功能。

标签语法

<cfset myQuery = ...>
<cfquery name="sortedQuery" dbtype="query">
  SELECT * FROM myQuery ORDER BY col1, col2 DESC;
</cfquery>

cfscript 语法

var myQuery = ...;
var sortedQuery = queryExecute("
   SELECT * FROM myQuery ORDER BY col1, col2 DESC;
", {}, {dbtype: "query"});

无论如何 - 如果您以正确的顺序插入行,则不需要对任何内容进行排序,因此在循环之前 pre-sorting data 将是您拥有的最有效的选择。