我有问题。我想通过使用来自其他查询列的值来减去查询的列值。
表格
import java.util.Stack;
public class StackSorting {
public static void main(String[] args) {
Stack<Integer> stack = new Stack<Integer>();
stack.push(12);
stack.push(100);
stack.push(13);
stack.push(50);
stack.push(4);
System.out.println("Elements on stack before sorting: "+ stack.toString());
stack = sort(stack);
System.out.println("Elements on stack after sorting: "+ stack.toString());
}
private static Stack<Integer> sort(Stack<Integer> stack) {
if (stack.isEmpty()) {
return null;
}
Stack<Integer> sortedStack = new Stack<Integer>();
int element = 0;
while(!stack.isEmpty()) {
if (stack.peek() <= (element = stack.pop())) {
if (sortedStack.isEmpty()) {
sortedStack.push(element);
} else {
while((!sortedStack.isEmpty()) && sortedStack.peek() > element) {
stack.push(sortedStack.pop());
}
sortedStack.push(element);
}
}
}
return sortedStack;
}
}
表损坏股票
ITEM BOX PLASTIC
ABC 2 0
DEF 0 15
GHI 1 5
JKL 0 10
预期结果(现货)
ITEM BOX PLASTIC
DEF 0 15
GHI 1 0
JKL 0 5
我尝试使用NOT IN SQL语句,但只能为所有3列隐藏相同的值。
什么SQL语句适合于减去每个列值而不显示任何记录(如果BOX&amp; PLASTIC是零。
答案 0 :(得分:2)
执行left join
检查可用性
select s.ITEM, IIF(s.box-ds.box is null, s.box, s.box-ds.box) BOX,
IIF(s.plastic-ds.plastic is null, s.plastic, s.plastic-ds.plastic) PLASTIC
from STOCK s
left join DAMAGEDSTOCK ds on ds.item = s.item
where IIF(s.box-ds.box is null, 1, s.box-ds.box) <> 0 OR
IIF(s.plastic-ds.plastic is null, 1, s.plastic-ds.plastic) <> 0