【问题标题】:How to get 2 aggregate functions in one FetchXML script?如何在一个 FetchXML 脚本中获得 2 个聚合函数?
【发布时间】:2014-11-03 21:21:22
【问题描述】:

假设我有一个数据集:

+--------+-------+----------+
| Animal | Price | FoodCost |
+--------+-------+----------+
|      1 |    23 |       22 |
|      1 |    32 |       33 |
|      1 |     7 |       69 |
|      2 |    45 |       55 |
|      2 |   432 |       82 |
|      2 |    33 |       34 |
|      3 |    67 |       44 |
|      5 |   671 |       62 |
|      8 |   234 |       43 |
+--------+-------+----------+

我在 tablix 中寻找的结果是:

+--------+-------+----------+
| Animal | Price | FoodCost |
+--------+-------+----------+
|      1 |    62 |      124 |
|      2 |   510 |      171 |
|      3 |    67 |       44 |
|      5 |   671 |       62 |
|      8 |   234 |       43 |
+--------+-------+----------+

我了解如何进行 1 次汇总,但我将如何进行 2 次汇总,即对每只动物的价格和食物成本求和?

【问题讨论】:

    标签: sql sql-server visual-studio reporting-services fetchxml


    【解决方案1】:

    SQL:

    select Animal, sum(Price) as Sum_Price, sum(FoodCost)  as sum_foodcost
    from dbo.AggegateTest
    group by Animal
    

    使用http://sql2fetchxml.com/生成FetchXML:

    <fetch aggregate="true" mapping="logical">
      <entity name="AggegateTest">
        <attribute name="Animal" alias="AggegateTest1.Animal" />
        <attribute name="price" alias="Sum_Price" aggregate="sum" />
        <attribute name="foodcost" alias="sum_foodcost" aggregate="sum" />
        <attribute name="Animal" alias="Animal" groupby="true" />
      </entity>
    </fetch>
    

    【讨论】:

      猜你喜欢
      • 2020-08-27
      • 2023-03-15
      • 2016-12-17
      • 2021-08-31
      • 2022-01-20
      • 1970-01-01
      • 2021-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多