我一直以为我不能,但MSDN说不然.
不使用GROUP BY时,HAVING的行为类似于WHERE子句.
我检查过并得到错误:
消息8121:
列'...'在HAVING子句中无效,因为它不包含在聚合函数或GROUP BY中.
那么,它是什么?文档中的错误或鲜为人知的细节?
这可能是Sybase SQL Server中可用的功能之一.现在微软重写SQL Server更接近ANSI标准,但忘了修复文档.
是这样的吗?
我认为现在最好显示代码:
class Foo
{
public ICollection<int> Ints1 { get; } = new List<int>();
public ICollection<int> Ints2 => new List<int>();
}
class Program
{
private static void Main(string[] args)
{
var foo = new Foo
{
Ints1 = { 1, 2, 3 },
Ints2 = { 4, 5, 6 }
};
foreach (var i in foo.Ints1)
Console.WriteLine(i);
foreach (var i in foo.Ints2)
Console.WriteLine(i);
}
}
Run Code Online (Sandbox Code Playgroud)
显然该Main方法应该打印1,2,3,4,5,6,但它只打印1,2,3.初始化后foo.Ints2.Count等于零.为什么?