0
I have a table that has the times of the day
SELECT * FROM horas
The type of the column hora
is VARCHAR(5)
And a query containing the values of the hours
SELECT DATE_FORMAT( date, '%H:%i' ) HORA ,TRUNCATE( MAX( humidade ),2 ) MAX_HUMIDADE ,TRUNCATE( MIN( humidade ),2 ) MIN_HUMIDADE FROM medicao WHERE DATE(date) = '2018-07-24' GROUP BY HOUR(date)
Whose result is this:
But by doing the
join
of the tables only comes a tupleSELECT * FROM HORAS A LEFT JOIN ( SELECT DATE_FORMAT( medicao.date, '%H:%i' ) HORA ,TRUNCATE( MAX( humidade ),2 ) MAX_HUMIDADE ,TRUNCATE( MIN( humidade ),2 ) MIN_HUMIDADE FROM medicao WHERE DATE(medicao.date) = '2018-07-24' GROUP BY HOUR(medicao.date) ) B ON B.HORA = A.HORA;
Whose result is:
I started that question here, if someone wanted to understand better
With the
query
that you did, the condition of taking the data from the two tables isB.HORA = A.HORA
. On the tablemedicacao
the values ofhoras
are closed values, such as00:00
,01:00
, ... . Then with thequery
that you did, the table valuesmedicacao
will only be united when thehora
tablehora
is the same. Note that the tablehora
, beyond closed hours, has minutes.– Thiago Magalhães
Truthful! Now that I realize that I have entered the wrong hours values. That’s right.
– adventistaam
Post that solved the problem to finalize the question.
– Thiago Magalhães
But it was you who helped me see, thank you very much! You can add the answer
– adventistaam