小编low*_*ern的帖子

如何将sql union转换为linq

我有一个使用union的以下Transact SQL查询.我需要一些关于在LINQ中看起来如何看的指针,即一些例子会很好或者如果有人可以在linq上推荐一个关于UNIONS的好教程.

select top 10 Barcode, sum(ItemDiscountUnion.AmountTaken) from
(SELECT d.Barcode,SUM(AmountTaken) AmountTaken
  FROM [Aggregation].[dbo].[DiscountPromotion] d

  GROUP BY d.Barcode

  UNION ALL

  SELECT i.Barcode,SUM(AmountTaken) AmountTaken
  FROM [Aggregation].[dbo].ItemSaleTransaction i

  group by i.Barcode)  ItemDiscountUnion

  group by Barcode
Run Code Online (Sandbox Code Playgroud)

请注意,原始SQL正在 合并 2个选择NOT连接它们.我需要知道如何合并结果,即删除重复项,并根据条形码对存在重复的行数值求和.

c# sql linq union

26
推荐指数
3
解决办法
5万
查看次数

标签 统计

c# ×1

linq ×1

sql ×1

union ×1