Select Advanced separated by hour

Asked

Viewed 107 times

0

I rode a SELECT to return some information from my table separated by time and date. Until this part is all working correctly. Now I need him to select the same data only from another date, being the same table.

Man SELECT:

SELECT  CONCAT('2015-07-27 ', Horas.Hora, ':00:00') as HORA, qtd_clique as CLIQUES, qtd_ligacoes as LIGACOES, qtd_form as FORM
FROM (
  SELECT '08' Hora UNION SELECT '09' UNION SELECT '10' UNION SELECT '11' UNION
    SELECT '12' UNION SELECT '13' UNION SELECT '14' UNION  SELECT '15' UNION
    SELECT '16' UNION SELECT '17' UNION SELECT '18' 
) Horas
LEFT JOIN relatorio_cliques C
    ON SUBSTRING(C.data_hora, 12, 2) = Horas.Hora
        AND C.data_hora LIKE '2015-07-27%' 
        AND C.cliente = 'cliente_teste'
GROUP BY CONCAT('2015-07-27 ', Horas.Hora, ':00:00')
ORDER BY 1;

The retro is this were:

HORA | CLIQUES | LIGACOES | FORM

I have the 3 columnars CLICKS, LINKS and FORM of the date 2015-07-27, now I would need the same information only of the day 2015-07-26, for example.

The return would be something like this:

HORA | CLIQUES(27-07) | CLIQUES(26-07) | LIGACOES(27-07) | LIGACOES(26-07) | FORM (27-07) | FORM (26-07)

I tried but I couldn’t, if anyone can help be very grateful.

  • 1

    Check this answer that should help you
 
 http://stackoverflow.com/questions/14834290/mysql-query-to-dynamically-convert-rows-to-columns

  • is it me or this duplicate ? /? http://answall.com/questions/92276/optimiza%C3%A7%C3%A3o-de-consulta-sql-no-mysql-e-index/93925? noredirect=1#comment190439_93925

  • @That’s when I rode the QUERY the one is optimization. After all this is from 2 months ago.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.