2
I have two tables, A and B. Na Table A, I have a column with names of machines (Cutter, Baler, Packer and Rewinder) and in the other column some causes that made them stop (As Lack of Electrical Power, Coil Exchange, etc).
In the Table B, I have a column listing all possible reasons (In Table A are just the ones that already occurred, each line shows the name of a machine and the reason for its stop.)
Goal:
Make the code return me the number of times a specific machine has been stopped for each reason, returning the value 0
if she hasn’t been stopped by that.
Current query:
SELECT
B.TodosOsMotivos,
A.MotivosQueAconteceram,
A.Maquinas,
COUNT(A.MotivosQueAconteceram) as NumeroDeOcorrencias
FROM A
RIGHT join B on A.MotivosQueAconteceram = B.TodosOsMotivos
WHERE A.Maquinas = 'Cortadeira'
OR A.Maquinas IS NULL
GROUP by MotivosQueAconteceram, Maquinas, B.TodosOsMotivos
order by B.TodosOsMotivos
That way she tells me how many times the Cutter stood still for an X reason and returns NULL
when no machine has stopped for any reason. The problem is that when the CUTTER didn’t stop for a Y reason but ANOTHER MACHINE stopped, it just doesn’t return any value to me, when I needed it to return to me 0/NULL
. What can I do to change that?
Tables:
That’s the Table A pa_maquina
refers to the Question Machines column and pa_motivos
refers to the column MotivosQueAconteceram
:
That’s the Table B, the column descricao
refers to the TodosOsMotivos
:
put the structure of the tables please, it is kind of strange that, the data are not normalized ?
– Rovann Linhalis
So just to understand. Do you want the number of times the CUTTER has been stopped and, if the machine is different, that I appear 0? It doesn’t make much sense, it’s not better to show the amount independent of the machine type?
– Sorack
Sorack, I need to form a chart for the cutter informing her stop index for each motif. Later it will be made individually for each machine. It turns out that when a reason happened to another machine and not to the one where I’m doing the graph, it doesn’t return 0 times when it stopped for that reason, it returns nothing, and so php doesn’t include that reason in the graph. So I would need some return value, even if 0.
– Renata
dvd, when used COUNT and do not use GROUP by gives error.
– Renata