-1
I have the following scenario.
I have a site where there are "partners" for this site.
Each partner has a specific url for it.
When someone accesses this link, with a specific url, something like "siteexample.com.br/? source=partner1&origem_code=P1 it saves this information in the database along with a code.
If the client registers, this code is also registered in the client table.
Now I need to calculate how many customers were registered from that partner.
Minha tentativa inicial foi essa, mas logo percebi que tenho que listar o conteúdo da origem.
select
(
SELECT
count(cli_id)
FROM
`qc_clientes`
join qc_origem_acesso on qc_origem_acesso.origem_unique_id = qc_clientes.cli_unique_id
left join qc_pedidos on qc_pedidos.ped_id = qc_clientes.cli_id
) AS `qtdAcessos`,
sum(qc_pedidos.ped_id) as qtdPedidos,
sum(qc_pedidos.ped_valor) as totalEmPedido,
sum(qc_pedidos.ped_valor) * 0.05 as valorDaComissao,
qc_pedidos.ped_data,
qc_pedidos.ped_pag_status,
qc_origem_acesso.origem_nome
from qc_clientes
join qc_origem_acesso on qc_origem_acesso.origem_unique_id = qc_clientes.cli_unique_id
left join qc_pedidos on qc_pedidos.ped_id = qc_clientes.cli_id
If anyone can help I’d be grateful