表联接的求和函数

时间:2019-01-21 17:59:25

标签: vb.net linq

尝试使用linq连接两个数据表,并按日期对特定列求和,并使用单独的唯一标识符

我尝试了一些按组的语句,我认为我从更基本的示例中缺少一些内容来完成查询。

Dim subquery = (From t1 In dt.AsEnumerable()
                    Join t2 In dt2.AsEnumerable() On
                        t1.Field(Of Decimal)(field1) Equals t2.Field(Of Decimal)(field1) And
                        t1.Field(Of Decimal)(field2) Equals t2.Field(Of Decimal)(field2) And
                        t1.Field(Of Decimal)(field3) Equals t2.Field(Of Decimal)(field3) And
                        t1.Field(Of String)(field4) Equals t2.Field(Of String)(field4) And                       
                        t1.Field(Of Decimal)(date) Equals t2.Field(Of Decimal)(date)
                    Where (t1.Field(Of Decimal)(field3) = 1) And (t2.Field(Of Decimal)(field3) = 1) And (t2.Field(Of String)("field7") = "A")
                    And (t1.Field(Of Decimal)("field7") = 533) And (t2.Field(Of Decimal)(date) > 20180101) And
                    (t2.Field(Of Decimal)(date) < 20190101) And (t1.Field(Of Decimal)(date) < 20190101) And (t1.Field(Of Decimal)(date) > 20180101)
                    Select New With {.JRNL = t1.Field(Of String)(jrnl), .amount = t2.Field(Of Decimal)("amount"),  .date = t1.Field(Of Decimal)(date),
                        .invoice = t1.Field(Of Decimal)(field2), .limiter = t2.Field(Of String)("field7")}).ToList()

我正在尝试将金额列(t2.field(十进制)(“金额”))与t1.field(字符串)(jrnl)和t2.field(十进制)(日期)求和并显示与t1。(jrnl)和t1。(date)一起使用,因此最终结果看起来像

jrnl   date     summed amount
a     20180101    500000

0 个答案:

没有答案