Join tables MySQL

0
  • I have a table that has the times of the day

     SELECT * FROM horas
    

ColumntypehoraisVARCHAR(5)

  • Andaquerycontainingthetimevalues

    SELECTDATE_FORMAT(date,'%H:%i')HORA,TRUNCATE(MAX(humidade),2)MAX_HUMIDADE,TRUNCATE(MIN(humidade),2)MIN_HUMIDADEFROMmedicaoWHEREDATE(date)='2018-07-24'GROUPBYHOUR(date)

Whoseresultisthis:

  • Butwhenyoudojoinoftablesonlyatuplecomes

    SELECT*FROMHORASALEFTJOIN(SELECTDATE_FORMAT(medicao.date,'%H:%i')HORA,TRUNCATE(MAX(humidade),2)MAX_HUMIDADE,TRUNCATE(MIN(humidade),2)MIN_HUMIDADEFROMmedicaoWHEREDATE(medicao.date)='2018-07-24'GROUPBYHOUR(medicao.date))BONB.HORA=A.HORA;

Theresultis:

Istartedthisquestion here if someone wanted to understand better

    
asked by anonymous 24.07.2018 / 20:20

1 answer

3

Reason for error:

With query you have done, the condition of getting the data from the two tables is B.HORA = A.HORA . In the medicacao table the values of horas are closed values, such as 00:00 , 01:00 , .... So with% w / o% you've done, the values of the query table will only be joined when the medicacao of the hora table is the same. See that the hour table, in addition to the closed hours, has the minutes.

    
24.07.2018 / 20:38