我熟悉SQL中的基本查询,但我需要应用过滤器,并且我不完全确定如何去解决这个问题。Linq to SQL过滤器匹配
我现在有这个疑问:
var query = (from solvedPuzzle in db.SolvedPuzzles
where solvedPuzzle.UserID == user.ID
select solvedPuzzle);
我想修改查询或筛选的结果是这样的伪代码:
for each pair (a,b) of results
if a.PuzzleID == b.PuzzleID
filter out a.NumberOfMoves > b.NumberOfMoves ? a : b
在情况并不简单不够,我我将给出过滤器的示例结果
Table SolvedPuzzles:
ID UserID PuzzleID NumberOfMoves
1 2 1 5
2 2 1 6 //Will be filtered out
3 2 2 7
4 3 1 8 //Will be filtered out
5 3 1 6
6 4 2 5
7 5 2 4
也就是说,这两个将被过滤出结果b因为它们是由同一个用户和同一个谜题组成的,但是具有更多的移动次数。
什么,你希望看到如果你有3个纪录为相同的用户/拼图组合?或者他们会一直是单身还是双人? – Ocelot20 2011-06-10 18:44:34