select
a.col1,
b.col2,
b.col3,
(case when b.sal > 0 and b.sal2 is not null then 1
when b.sal < 0 b.sal2 is not null then -1
else 0
end) sal,
sum(a.col4) sal_2,
sum(a.col5) sal_3
from a, b
where a.col_009 = b.col_008
group by
a.col1,
b.col2,
b.col3,
(case when b.sal > 0 and b.sal2 is not null then 1
when b.sal < 0 b.sal2 is not null then -1
else 0
end)
-----------------------OR----------------------
select
a.col1,
b.col2,
b.col3,
(case when b.sal > 0 and b.sal2 is not null then 1
when b.sal < 0 b.sal2 is not null then -1
else 0
end) sal,
sum(a.col4) sal_2,
sum(a.col5) sal_3
from a, b
where a.col_009 = b.col_008
group by
a.col1,
b.col2,
b.col3,
b.sal,
b.sal2
|