我有 3 个表,我将引用这些表来创建一个表 - 称为最后创建的输出报告- 我需要一些关于我的过程是否有意义的指导:
表 1:批次
| 批次名称 | 批号 | 批次_数量 |
|---|---|---|
| ABC01 | 123A | 50 |
| ABC02 | 123B | 100 |
| ABC03 | 123C | 20 |
表 2:Txn_History
| 批号 | Txn_Type | Txn_数量 |
|---|---|---|
| 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 |
|---|---|---|
| 屈服 | 1 | 屈服 |
| 气泡 | 2 | 废料 |
| 翘曲 | 3 | 废料 |
| 弯曲 | 4 | 废料 |
表 4:输出报告
| 批次名称 | 批次_数量 | 屈服 | 气泡 | 翘曲 | 弯曲 |
|---|---|---|---|---|---|
| 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
不幸的是,我没有按预期填充值。我的查询中是否缺少某些内容,或者我是否错误地处理了这种情况?
谢谢您的帮助