I need help to build a query that brings data from 5 other tables. I will try to be as clear as possible, if information is missing, please let me know.
Come on:
I have the Media table: link
and the Proposals table: link
The other 3 tables are quiet, as I need only bring a field, not needing sums or any other function.
The result should be this:
My current query is this:
SELECT
data_proposta,
propostas.source_code,
sum(midias.custo) as custo,
COUNT(data_proposta) AS propostas,
SUM(if(precog_FK <> 9, 1, 0)) AS validas
FROM propostas
LEFT JOIN midias
ON 'data_proposta' = 'midias'.'data'
GROUP BY data_proposta
I'm having problems when I have to make the sum of the costs of the media table.