LINQ to SQL 分组和计数
我已经寻找解决方案,但没有类似的。 我的问题是我想从数据库中选择数据,按用户 ID 对其进行分组并按状态 ID 对其进行计数
用户
UserID
Name
约会
UserID
ClientID
Status
StartDate
状态可以是活动 = 1,取消 = 2,完成 = 3
这就是我显示结果的方式。
提前致谢。
I have searched for solution, but nothing similar.
My problem is that I want to select data from database, group it by UserID and Count it by Status id
Users
UserID
Name
Appointments
UserID
ClientID
Status
StartDate
Status can be active=1, canceled=2, done=3
This is how I will display results.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的问题中,您说您想要对
UserId
进行分组,但在输出中您显示Name
。此查询将对两者进行分组。您可能想根据您的需要进行调整。(如果两个用户具有相同的名称,这将处理这种情况)
In you question you say you want to group on
UserId
, but in the output you showName
. This query will group on both. You might want to adjust it to your needs.(this will handle the case if two users have the same name though)
这涵盖了分组运算符。 这涵盖了计数。
This covers grouping operators. This covers the count.