简体   繁体   English

选择每个用户和日期仅一行

[英]Select Only one row per user and date

i want to select only one row per user and date 我只想为每个用户和日期选择一行

so if the data like this 所以如果这样的数据

ID  User    Date
25  3597    2014-09-04 13:37:12.953
26  2100    2014-09-04 13:37:29.820
27  3597    2014-09-04 13:38:12.953
28  2100    2014-09-04 13:38:29.820
29  3597    2014-09-05 13:40:12.953
30  2100    2014-09-05 13:40:29.820

the result should be 4 结果应该是4

The result should be 4 结果应为4

If all you need is the count, in SQL, you can use COUNT(DISTINCT) , like this: 如果只需要计数,则在SQL中,可以使用COUNT(DISTINCT) ,如下所示:

SELECT COUNT(DISTINCT User, Date) FROM MyTable

In LINQ, you can use GroupBy followed by Count : 在LINQ中,可以使用GroupBy然后使用Count

int cnt = src.Items.GroupBy(item => new {i.User, i.Date}).Count();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM