4
我想查询使用LINQ此表:Linq查询与多个计数
这就是我想做的事:
这里是我的LINQ查询:
var query = from a in table
where a.Country.Equals("USA")
group a by a.Product_brand into grp
select new
{
Product_brand = grp.key.Product_brand,
Country = grp.Key.Country,
Black = grp.Count(a => a.Black=="Yes"),
White = grp.Count(a => a.White=="Yes"),
Red = grp.Count(a=> a.Red=="Yes"),
Green = grp.Count(a=> a.Green=="Yes")
}
我不知道我的问题有什么问题RY,我不断收到这样的信息:
替代解决方案:
SQL查询:
SELECT [Product brand], Country,
sum(case when [Black] = 'Yes' then 1 else 0 end) as Black,
sum(case when [White] = 'Yes' then 1 else 0 end) as White,
sum(case when [Red] = 'Yes' then 1 else 0 end) as Red,
sum(case when [Green] = 'Yes' then 1 else 0 end) as Green,
FROM dbo.Table
group by [Product brand], Country
这似乎没有在linq的一些问题,也许它在你的连接。 –
您的服务器已关闭或无法访问?你的查询看起来很好:只要你的表的大小不在数十亿行中,你就应该很快得到你的结果。 – dasblinkenlight
服务器肯定没有关闭,我只是测试了连接它正在工作 – Zack09