查看: 1938|回复: 2
|
linq count query 问题
[复制链接]
|
|
在还没整理前(absence=1,present=0)
student name absence times
ah beng 1
ah beng 1
ah gao 0
ah gao 1
ah gao 0
我想加query 限制 我的 datagridview只显示 student absence超过2次
结果:
student name absence times
ah beng 2
这是我的 query,不懂错哪里
Private Sub bindData()
Dim db As New DBDataContext()
dgv.DataSource = From row As DataRow In dgv.Rows.Cast(Of DataRow)()
Group row By r = row.Field(Of String)("studentName") Into Group
Select New With {
.Resource = r,
.totalHours = Group.Sum(Function(dr) dr.Field(Of Decimal)("Time of absence"))
}
End Sub
|
|
|
|
|
|
|
|
发表于 27-8-2014 06:32 AM
|
显示全部楼层
不会linq....
但是在 SQL 是这样的,你自己翻译看
SELECT name, SUM(absence)
FROM student
WHERE date BETWEEN '2014-05-01' AND '2014-05-30'
GROUP BY student_id
HAVING SUM(absence) >2
觉得是 ‘HAVING ’ 的问题...希望帮到你....
本帖最后由 pohlee 于 27-8-2014 06:36 AM 编辑
|
|
|
|
|
|
|
|
发表于 27-8-2014 09:38 PM
|
显示全部楼层
不是很熟,
http://stackoverflow.com/questions/14142256/sum-and-group-linq
var query = from v in paxes.Select(p => p.Voucher)
group v by new {v.VoucherDesc, v.VoucherCode } into g
select new {
Desc = g.Key.VoucherDesc,
Code = g.Key.VoucherCode,
Total = g.Sum(x => x.Price)
};
本帖最后由 gkheng2003 于 27-8-2014 09:41 PM 编辑
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|