来自数据表的统计数据
使用 VB .NET,我想知道从数据表中获取一些统计数据的最佳方法。我宁愿不使用另一个查询来访问数据库,而只是查看我已有的数据表。
那么,Linq 一定是答案吗?
我有一个包含两列的数据表(dtable):tech_id 和 color。由此,我想要一个包含三列的新数据表:tech_id、color 和 count。当然,我试图找出每个“tech_id”使用每种不同“颜色”的次数。例如:
tech_id colour count
------------------------------
JM brown 18
JM purple 10
JM green 3
PB brown 51
PB grey 8
TD brown 4
TD pink 67
TD grey 41
我对 Linq 的最佳尝试根本不正确,但粘贴在下面以显示我已经走了多远:
Dim ColourCounts = From p In PGWorkingDataTable.AsEnumerable() _
Group p By p.Field(Of String)("colour") Into Count() _
Select tech_id, colour, ColourCount = Count
Dim colourStatsTable As DataTable = ColourCounts.CopyToDataTable()
谢谢您的帮助!
Using VB .NET, I am wondering about the best way to get some statistical data out of a Datatable. I would rather not hit the database with another query, but just look through the datatable I already have.
So, Linq must be the answer?
I have a datatable (dtable) containing two columns: tech_id and colour. From this, I would like a new datatable containing three columns: tech_id, colour, and count. Of course, I'm trying to figure out how many times each "tech_id" used each distinct "colour". Something like:
tech_id colour count
------------------------------
JM brown 18
JM purple 10
JM green 3
PB brown 51
PB grey 8
TD brown 4
TD pink 67
TD grey 41
My best attempt with Linq is not at all correct, but is pasted below to show how far I've gotten:
Dim ColourCounts = From p In PGWorkingDataTable.AsEnumerable() _
Group p By p.Field(Of String)("colour") Into Count() _
Select tech_id, colour, ColourCount = Count
Dim colourStatsTable As DataTable = ColourCounts.CopyToDataTable()
Thank you for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看
如何使用 LINQ 来汇总此数据 - 按这些关系的计数分组的关系数量
Check out
How can I use LINQ to summarize this data--number of relationships grouped by the count of those relationships