I want to know the average values (value2) in a table using AVG () (or another form).
I have a table in MYSQL with the columns id, total_value, valuem2 (Value per m²), and area.
In some lines the value m2 is empty and in others the total value is empty.
Is there any way to do a select if the field is empty, does it make an account? Type the below:
tabela_terrenos
id|valortotal|valorm2|area
1 |100000 | 1000 |100
2 |150000 | |100
3 | | 1500 |200
SE valorm2 = vazio, então valorm2 = valortotal / area
SENÃO valorm2 = valorm2
SELECT AVG(valorm2)
FROM tabela_terrenos