sqlplus - oracle sql plus script is too long -
select (select sum(t.fees_amount)from unit u, payment p, type_of_fees t u.unit_id = p.unit_id , p.stof = t.stof , u.unit_id '%u1001%' , p.stat = 'not payed') "block 1(not payed)", (select sum(t.fees_amount)from unit u, payment p, type_of_fees t u.unit_id = p.unit_id , p.stof = t.stof , u.unit_id '%u1001%' , p.stat = 'payed') "block 1(payed)", (select sum(t.fees_amount)from unit u, payment p, type_of_fees t u.unit_id = p.unit_id , p.stof = t.stof , u.unit_id '%u1002%' , p.stat = 'not payed') "block 2(not payed)", (select sum(t.fees_amount)from unit u, payment p, type_of_fees t u.unit_id = p.unit_id , p.stof = t.stof , u.unit_id '%u1002%' , p.stat = 'payed') "block 2(payed)" dual;
is there other method deal this?
you can use conditional aggregation this:
select sum(case when u.unit_id '%u1001%' , p.stat = 'not payed' t.fees_amount else 0 end) "block 1(not payed)", sum(case when u.unit_id '%u1001%' , p.stat = 'payed' t.fees_amount else 0 end) "block 1(payed)", sum(case when u.unit_id '%u1002%' , p.stat = 'not payed' t.fees_amount else 0 end) "block 2(not payed)", sum(case when u.unit_id '%u1002%' , p.stat = 'payed' t.fees_amount else 0 end) "block 2(payed)" unit u join payment p on u.unit_id = p.unit_id join type_of_fees t on p.stof = t.stof;
also should use explicit join syntax instead of old comma based joins.
Comments
Post a Comment