我发现ColdFusion的查询组件有一些非常奇怪的行为.当您使用此组件构建另一个ColdFusion查询的查询(QoQ)查询并order by在多个列上使用时,order by列表中的最后一列将添加到所选输出中.这似乎发生在CF9,10,11和2016,但不是Lucee.
/* Create an unsorted CF-query */
unsorted = QueryNew("col1,col2,col3,col4","VarChar,VarChar,Integer,VarChar");
for (a=10;a gte 1;a--){
QueryAddRow(unsorted);
QuerySetCell(unsorted,"col1","col1 #a#");
QuerySetCell(unsorted,"col2","col2 #a#");
QuerySetCell(unsorted,"col3","#a#");
QuerySetCell(unsorted,"col4","col4 #a#");
}
writeDump(var="#unsorted#");
/* Create a new CF query of query with the unsorted table */
sorted = new query(
dbtype = "query"
,unsorted = unsorted
,sql = "select [col1],[col2] from unsorted order by [col3], [col4] asc"
).execute().getresult();
/* The last column in the order by list will be displayed in …Run Code Online (Sandbox Code Playgroud) 我正在尝试进行SQL查询,其中'exists'子句中的子查询具有'having'子句.奇怪的是.没有错误,子查询作为独立查询.但是,整个查询给出了与'having'子句完全相同的结果.
这是我的查询的样子:
SELECT X
FROM A
WHERE exists (
SELECT X, count(distinct Y)
FROM B
GROUP BY X
HAVING count(distinct Y) > 2)
Run Code Online (Sandbox Code Playgroud)
所以我试图从A中选择行,其中X在B中有两个以上的Y出现.但是,结果还包括子查询中不存在的记录.我在这做错了什么?