我有一份关于生产的表格报告,我希望在QTY
字段上的负值和正值之间架起桥梁。
我想创建一个具有正值的新列,以及从QTY
字段中选择负值的另一列。
mtl_trx qty uom
1 20 1230 KG
2 39 950 KG
3 45 100 LBR
4 91 250 KG
5 118 -500 KG
6 125 -284 KG
7 137 -120 KG
8 143 -80 KG
答案 0 :(得分:0)
如果我理解正确,你想选择两列,一列显示正值,一列显示负值?使用案例构造来决定是否显示值。
select mtl_trx, qty, uom,
case when qty > 0 then qty end as qty_pos,
case when qty < 0 then qty end as qty_neg
from mytable;
答案 1 :(得分:0)
select mtl_trx, qty, uom,
case when qty > 0 then qty else 0 end as positive,
case when qty < 0 then qty else 0 end as negative
from production;