在一列中给定具有相同值的行 [英] count rows given same value in one column
问题描述
你好,
如果特定列中有重复值,我需要计算行数
例如
姓名|持续时间
约翰| 20
玛丽| 40
莉娜| 50
约翰| 10
约翰| 20
玛丽| 10
我希望结果是这样
姓名|卷最长
约翰| 3 | 20
玛丽| 2 | 40
莉娜| 1 | 50
即时通讯使用访问数据库.我将数据放在数据表中.计算完我想要的内容后,我会将其插入到新数据库中...
有什么办法可以实现呢?
感谢您的提前帮助.
hi there,
I need to count the number of rows if there is a duplicate value in a specific column
for example
Name | Duration
John | 20
Mary | 40
Lena | 50
John | 10
John | 20
Mary | 10
i want the results to be this way
Name | vol | Longest
John | 3 | 20
Mary | 2 | 40
Lena | 1 | 50
im using access database. I put the data in a datatable. after calculating what i want i will insert it into new database...
is there any way i can achieve this?
Thanks for you help in advance
推荐答案
尝试:
SELECT Name, COUNT(Duration) as Vol, MAX(Duration) as Longest FROM MyTable Group by Name
从TableName组中按名称选择Name,count(Duration)as vol,max(Duration)as Longest
select Name,count(Duration)as vol, max(Duration) as Longest from TableName group by Name
foreach (DataRow row in dt.Rows)
{
var nameCo = from c in dt.AsEnumerable()
group c by c.Field<string>("yName") into g
select new
{
Name = g.Key,
List = g.ToList(),
} into g
select new
{
g.Name,
Count = g.List.Count,
durAve = g.List.Average(x => x.Field<int>("Duration")),
durMax = g.List.Max(y => y.Field<int>("Duration"))
};
foreach (var summary in nameCo)
{
Console.WriteLine("Name:" + summary.Name.ToString() + ", Volume:" + summary.Count.ToString() + ",Average:" + summary.durAve.ToString() + "Longest duration: " + summary.durMax.ToString());
}
这篇关于在一列中给定具有相同值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!