3
I got three tables a call CRM_PROCESSO
, another call CRM_PROCESSO_VARIAVEL
and the last call CRM_PROCESSO_ATIVIDADE
, both have the variable idprocesso
in common.
What I need is for command to bring the field IDPROCESSO
, USUARIO
, DATAINICIO
, DATATERMINO
table CRM_PROCESSO
,the field DESCRICAO
table CRM_PROCESSO_ATIVIDADE
and the countryside valoratual
table CRM_PROCESSO_VARIAVEL
I was able to do the command, but with the separate data.
I turned the remote down, and I brought the field IDPROCESSO
, USUARIO
, DATAINICIO
, DATATERMINO
table CRM_PROCESSO
,the field DESCRICAO
table CRM_PROCESSO_ATIVIDADE
, when they both have the IDPROCESSO
equal.
select crm_processo.idprocesso,
crm_processo.usuario,
crm_processo.datainicio,
crm_processo.datatermino,
crm_processo_atividade.descricao
from crm_processo join crm_processo_atividade on (crm_processo_atividade.idprocesso = crm_processo.idprocesso and crm_processo_atividade.idatividade = crm_processo.idatividadeatual) where status = 1 and idprocedimento = 34 and idatividadeatual <>2
And I managed to make the command below, bringing the field valoratual
table CRM_PROCESSO_VARIAVEL
(I used an example with IDPROCESSO = 39)
SELECT cpv.descricao,
cpv.valoratual,
(CASE CPV.DESCRICAO
WHEN '/*MOTIVOCANCELAMENTO*/' THEN 'Motivo Cancelamento'
END) from crm_processo_variavel cpv where idprocesso = 3089 AND CPV.DESCRICAO IN ('/*MOTIVOCANCELAMENTO*/')
But honestly, I don’t know how to put the two commands together.
The process x activity ratio is 1 to 1. And variable x process also 1 to 1.
Someone can help me ?
The process-activity relation is
1 para 1
? And process x variable too1 para 1
? Or is1 para 0
, or1 para muitos
? It is important to know the multiplicity of relations so you know whether you will do a JOIN or an OUTER JOIN to retrieve the records in a single query. Edit the question and inform the multiplicities.– Pagotti
Hello @Pagotti the process x activity ratio is 1 to 1. And process x variable also 1 to 1.
– Renan Vieira
There is something strange because in your original query you have
crm_processo_atividade.idatividade = crm_processo.idatividadeatual
. If it is1 para 1
because you have thisidatividadeatual
? Each process can have more than 1 activity?– Pagotti
The
crm_processo_variavel
also has a description filter. This means that eachcrm_processo_variavel
is also1 para muitos
? And you’re applying the filters to result in only 1 process record. That’s it?– Pagotti
A cool tool you can use when you have questions like this is the Dbfiddle. There you can put the structure and sample data of the tables and then share the question to facilitate who will help you. Also tag which bank you’re using.
– Pagotti