-1
I have the following SQL that correctly counts the number of properties:
select
clientes.id,
clientes.nome,
clientes.status,
clientes.cliente,
clientes.tipo,
clientes.disponibilidade,
imoveis.id,
imoveis.cod,
imoveis.status,
imoveis.vvenda,
COUNT(imoveis.id) AS imoveis
from clientes
inner join imoveis on clientes.cliente = imoveis.cod
where
imoveis.status='2'
AND clientes.status='2'
AND imoveis.vvenda < clientes.disponibilidade
AND imoveis.vvenda <> '0'
AND clientes.cliente = '$cliente'
AND imoveis.cod = '$cliente'
GROUP BY clientes.id
Only that I had to make a small implementation (I highlighted below what I added) only that the number of properties is now incorrect in the count. See below the SQL with implementations:
select
clientes.id,
clientes.nome,
clientes.status,
clientes.cliente,
clientes.tipo,
clientes.disponibilidade,
imoveis.id,
imoveis.cod,
imoveis.status,
imoveis.vvenda,
COUNT(imoveis.id) AS imoveis,
photos.Cod
from clientes
inner join imoveis on clientes.cliente = imoveis.cod
Inner Join photos on photos.Cod=immobles.id
where
imoveis.status='2'
AND clientes.status='2'
AND imoveis.vvenda < clientes.disponibilidade
AND imoveis.vvenda <> '0'
AND clientes.cliente = '$cliente'
AND imoveis.cod = '$cliente'
GROUP BY clientes.id
These simple implementations were enough for the property count to be totally different.
I really need help!
The value is different as? Higher or lower than the value "correct", what is the relationship between photo and immovable? 1 for 1, 1 for N?
– Rubico
What is the criterion that the personnel is using to negatively? The person who negatively could inform their motives here?
– Rubico
@Rubico The value is different in the quantity of filtered properties. In the first example COUNT(immovables.id) Immovable AS displays perfectly the number of properties. In the second example, just because I made the small implentations the COUNT(immovel.id) Immovables displays totally different values, ie incorrect.
– Gladison Neuza Perosini
without a knowledge of your bank is a little difficult, but I noticed that you are comparing the
foto.codwith theimovel.id, would not be with theimovel.cod? Try to show what is the structure of your bank, what are the relationships.– Rubico
What you have valved is now valid. As there is a relationship between photo properties (where a property can have several photos), it is necessary that, in the table of photos, there is a column to store which property is the "owner" of the photo, that is, in the table of photos there must be a column
fotos.imovel_cod, for example, and it should be through this column that theinner joinbe done (INNER JOIN fotos ON fotos.imovel_cod = imovel.cod). How is the structure of the table photos? There is this column to make the relationship between photos and real estate?– Márcio Lordelo