【问题标题】:Mutiple tables with one data type broken down具有一种数据类型的多个表已分解
【发布时间】:2021-06-22 03:57:23
【问题描述】:

我有 3 个表格,我将引用这些表格来创建一个表格 - 称为 Output Report 最后能够创建 - 我需要一些关于我的流程是否有意义的指导:

表 1:批次

Lot_Name Lot_ID Lot_Qty
ABC01 123A 50
ABC02 123B 100
ABC03 123C 20

表 2:Txn_History

Lot_ID Txn_Type Txn_Qty
123A 1 5
123A 2 10
123A 3 5
123B 1 10
123B 2 5
123B 3 10
123C 1 5
123C 1 10
123C 2 5
123C 4 10

表 3:Txn_info

Txn_Name Txn_Type Txn_grp
Yield 1 Yield
Bubble 2 Scrap
Warping 3 Scrap
Bent 4 Scrap

表 4:输出报告

Lot_Name Lot_Qty Yield Bubble Warping Bent
ABC01 50 5 10 5 0
ABC02 100 10 5 10 0
ABC03 20 15 5 0 10

我的查询如下:

-- Create Table Output_Report
Select l.lot_name, l.lot_qty, 
sum(case when ti.txn_type = '1' then th.txn_qty yield end) as Yield,
sum(case when ti.txn_type = '2' then th.txn_qty yield end) as Bubble,
sum(case when ti.txn_type = '3' then th.txn_qty yield end) as Warping,
sum(case when ti.txn_type = '4' then th.txn_qty yield end) as Bent
from lot l
join txn_history th on l.lot_id=th.lot_id
join txn_info ti on th.txn_type=ti.txn_type
Group by l.Lot_Name

不幸的是,我没有按预期获得要填充的值。我的查询中是否缺少某些内容,还是我错误地处理了这种情况?

感谢您的帮助

【问题讨论】:

  • 将 l.lot_qty 添加到您的 group by 子句应该可以解决问题,即group by l.lot_name, l.lot_qty
  • 如果回复回答了您的具体问题,请不要忘记将答案标记为已接受。这有助于其他用户找到类似问题的答案。我注意到您已经提出了 11 个问题,但没有一个问题被接受。

标签: sql ssrs-2008


【解决方案1】:

在这种简单的情况下,您不需要转置数据,您可以让 SSRS 来做。

将数据集查询更改为

Select l.lot_name, l.lot_qty, ti.Txn_Type, ti.Txn_Name, th.txn_qty
from lot l
join txn_history th on l.lot_id=th.lot_id
join txn_info ti on th.txn_type=ti.txn_type

在您的报告中,使用矩阵而不是表格,将 lot_name 字段拖到“行”占位符,将 txn_name 拖到“列”占位符,将 txn_qty 拖到“数据”占位符。如果您希望列的顺序准确无误,请双击列组(在主设计窗口下)并将排序更改为按 txn_type 而不是 txn_name 排序。

要添加 lot_qty,请右键单击 lot_no 单元格并执行“插入列,在组内 - 右侧,然后在新单元格中从下拉列表中选择 lot_qty。

这是从内存中完成的,因此可能不是 100%。如果这不起作用,请发表评论,我将模拟设计,以便您查看它的外观。

【讨论】:

    猜你喜欢
    • 2021-12-27
    • 2016-05-30
    • 1970-01-01
    • 2021-10-16
    • 2022-11-28
    • 2018-02-17
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多