0

这是我想到的一个示例。当您使用聚合函数查询 tbl 时,您应该是这个 Result

Tally 聚合函数

Table: tbl  

Tag length              
abc 8               
cde 8               
fgh 10      

SQL:

SELECT aggTally(Tag, Length) FROM tbl   

结果:

2/8   
1/10            

我对 C# 很陌生,所以如何创建它并使用 dll?

4

2 回答 2

0

我没有看到上面提到的标签是如何使用的,但是下面的代码返回

2/8 1/10

->

    private static void TotalsByLength()
    {
        List<Tuple<string, int>> tagdata = new List<Tuple<string, int>>
        {
            new Tuple<string, int>("abs", 8),
            new Tuple<string, int>("cde", 8),
            new Tuple<string, int>("fgh", 10)
        };

        var tagcounts = from p in tagdata
            group p.Item2 by p.Item2 into g
            orderby g.Count() descending
            select new { g.Key, TotalOccurrence = g.Count() };

        foreach (var s in tagcounts)
        {
            Console.WriteLine("{0}/{1}", s.TotalOccurrence, s.Key );
        }
    }
于 2019-07-12T16:05:33.303 回答
0

T-SQL 方法:

CREATE TABLE dbo.TestTable (tag CHAR(3), taglen INT)
GO

INSERT INTO dbo.TestTable VALUES ('abs',8), ('cde', 8), ('fgh',10)
GO

;WITH TagTotal AS (SELECT taglen, COUNT(*) AS totallengthbytag
FROM dbo.TestTable
GROUP BY taglen)
SELECT a.totallengthbytag, a.taglen
FROM TagTotal a
于 2019-07-12T21:39:37.730 回答