0
I need to make a conditional select that checks a sum performed that way:
select round(sum((`gin`.`Caixa_9L` / 1000)),1) AS `total` from `gin`
If this sum above is = 0, I need to take a value of a field in another table (called asterisk) and display as total.
I’m starting in sql and I’m having a little trouble defining this logic.
You referenced in from only the gin table, the asterisk table does not need? When I spin here, it tells me that gin.asterico does not exist.
– Bene
Friend, I tested the code with some adaptations and this occurring the following: When the Box field_9l has a value registered as zero, the query does not add * but 0.0, when the Box field_9l contains at least 1 (a unit), it puts *. What can be this?
– Bene
select 
marca,
case 
 gin.Caixa_9L when (round(sum(caixa_9l/1000),1)= 0) then (select asterisco.asterisco from asterisco)
else
 (round(sum((Caixa_9L/1000)),1))
end
as valor
from gin
where sales_channel = 'duty paid' or sales_channel = 'travel retail'
group by marca
My query looked like this.– Bene