【发布时间】: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 个问题,但没有一个问题被接受。