在SQLSERVER 2005中,我使用表值函数作为从大表(传递日期范围或此类参数)对子集数据执行任意聚合的便捷方式.
我在大型查询中使用这些作为联合计算,我想知道查询计划优化器是否在每种情况下都能很好地与它们配合使用,或者我是否更好地在我的大型查询中取消这样的计算.
代码示例:
create table dbo.customers (
[key] uniqueidentifier
, constraint pk_dbo_customers
primary key ([key])
)
go
/* assume large amount of data */
create table dbo.point_of_sales (
[key] uniqueidentifier
, customer_key uniqueidentifier
, constraint pk_dbo_point_of_sales
primary key ([key])
)
go
create table dbo.product_ranges (
[key] uniqueidentifier
, constraint pk_dbo_product_ranges
primary key ([key])
)
go
create table dbo.products (
[key] uniqueidentifier
, product_range_key uniqueidentifier
, release_date datetime
, constraint pk_dbo_products
primary key ([key])
, constraint fk_dbo_products_product_range_key …Run Code Online (Sandbox Code Playgroud) t-sql sql-server sql-server-2005 query-optimization user-defined-functions
我正在尝试在vb.net中编写一个linq到对象查询,这是我正在尝试实现的c#版本(我在linqpad中运行它):
void Main()
{
var items = GetArray(
new {a="a",b="a",c=1}
, new {a="a",b="a",c=2}
, new {a="a",b="b",c=1}
);
(
from i in items
group i by new {i.a, i.b} into g
let p = new{ k = g, v = g.Sum((i)=>i.c)}
where p.v > 1
select p
).Dump();
}
// because vb.net doesn't support anonymous type array initializer, it will ease the translation
T[] GetArray<T>(params T[] values){
return values;
}
Run Code Online (Sandbox Code Playgroud)
我很难使用不同的语法组(vb在某些地方需要'identifier = expression',以及带''表达式'的求和算子')
非常感谢你的帮助!