SELECT A.NO_OF,b.sum2-a.sum1 FROM( select NO_OF,sum(customer) sum1 FROM test WHERE status='S' group by NO_OF) A, (select NO_OF,sum(customer) sum2 FROM test WHERE status='E' group by NO_OF) B WHERE A.NO_OF=B.NO_OF
更完整点的SELECT A.NO_OF,NVL(b.sum2-a.sum1,0) FROM( select NO_OF,sum(customer) sum1 FROM test WHERE status='S' group by NO_OF) A, (select NO_OF,sum(customer) sum2 FROM test WHERE status='E' group by NO_OF) B WHERE A.NO_OF(+)=B.NO_OF UNION SELECT A.NO_OF,NVL(b.sum2-a.sum1,0) FROM( select NO_OF,sum(customer) sum1 FROM test WHERE status='S' group by NO_OF) A, (select NO_OF,sum(customer) sum2 FROM test WHERE status='E' group by NO_OF) B WHERE A.NO_OF=B.NO_OF(+)
select a.NO_OF,b.CUSTOMER-a.CUSTOMER CUSTOMER from (select * from table_name where STATUS='s') a, (select * from table_name where starus='e') b where a.NO_OF=b.NO_OF
sorry,更正 SELECT NVL(A.NO_OF,B.NO_OF),b.sum2-NVL(a.sum1,0) FROM( select NO_OF,sum(customer) sum1 FROM test WHERE status='S' group by NO_OF) A, (select NO_OF,sum(customer) sum2 FROM test WHERE status='E' group by NO_OF) B WHERE A.NO_OF(+)=B.NO_OF UNION SELECT NVL(B.NO_OF,A.NO_OF), NVL(b.sum2,0)-a.sum1 FROM( select NO_OF,sum(customer) sum1 FROM test WHERE status='S' group by NO_OF) A, (select NO_OF,sum(customer) sum2 FROM test WHERE status='E' group by NO_OF) B WHERE A.NO_OF=B.NO_OF(+)
select NO_OF,sum(customer) sum1 FROM test WHERE status='S' group by NO_OF) A,
(select NO_OF,sum(customer) sum2 FROM test WHERE status='E' group by NO_OF) B
WHERE A.NO_OF=B.NO_OF
select NO_OF,sum(customer) sum1 FROM test WHERE status='S' group by NO_OF) A,
(select NO_OF,sum(customer) sum2 FROM test WHERE status='E' group by NO_OF) B
WHERE A.NO_OF(+)=B.NO_OF
UNION
SELECT A.NO_OF,NVL(b.sum2-a.sum1,0) FROM(
select NO_OF,sum(customer) sum1 FROM test WHERE status='S' group by NO_OF) A,
(select NO_OF,sum(customer) sum2 FROM test WHERE status='E' group by NO_OF) B
WHERE A.NO_OF=B.NO_OF(+)
(select * from table_name where STATUS='s') a,
(select * from table_name where starus='e') b
where a.NO_OF=b.NO_OF
SELECT NVL(A.NO_OF,B.NO_OF),b.sum2-NVL(a.sum1,0) FROM(
select NO_OF,sum(customer) sum1 FROM test WHERE status='S' group by NO_OF) A,
(select NO_OF,sum(customer) sum2 FROM test WHERE status='E' group by NO_OF) B
WHERE A.NO_OF(+)=B.NO_OF
UNION
SELECT NVL(B.NO_OF,A.NO_OF), NVL(b.sum2,0)-a.sum1 FROM(
select NO_OF,sum(customer) sum1 FROM test WHERE status='S' group by NO_OF) A,
(select NO_OF,sum(customer) sum2 FROM test WHERE status='E' group by NO_OF) B
WHERE A.NO_OF=B.NO_OF(+)