【问题标题】:Formula containing single and multiple results包含单个和多个结果的公式
【发布时间】:2017-09-13 06:11:21
【问题描述】:

我的报告使用两个表格。第一个表有一个值,第二个表有多个。如何制作一个公式,显示第一个表中的单个值,以及第二个表中的多个值的总和?

这两个表中的数据来自 Excel 上传。因此,这两个表中的某些数据没有匹配值。一些数据具有匹配值。我想要报告中的这两个数据。

【问题讨论】:

    标签: sql sql-server vb.net crystal-reports


    【解决方案1】:

    我认为您可以在 SQL 查询中计算它,如下所示:

    select 
      [Code], [Name], 
      sum(case when ord = 1 then amount else 0 end) as Amount1,
      sum(case when ord = 2 then amount else 0 end) as Amount2
    from (
      select [Code], [Name], [Amount1] amount, 1 ord
      from table1
      union all
      select [Code], [Name], [Amount2], 2
      from table2
    ) t
    group by
      [Code], [Name];
    

    SQL Fiddle Demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      • 2017-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多