Conditional select that takes value from another table

0

I need to do a conditional select that checks a sum done this way:

select round(sum(('gin'.'Caixa_9L' / 1000)),1) AS 'total' from 'gin'

If this sum above is = 0, I need to get a value from one field in another table (called an asterisk) and display as total.

I'm starting in sql and I'm having a bit of trouble defining this logic.

    
asked by anonymous 07.04.2017 / 15:36

1 answer

2
select case CAIXA_9L when ( round(sum((Caixa_9L / 1000)),1)  = 0 ) then
     ( select outrocampo from asterico ) /* não pode retornar mais de um registro esse subselect */ 
else
     ( round(sum((Caixa_9L / 1000)),1)  = 0 )
end as total from gin
    
07.04.2017 / 19:54