Guest User

Untitled

a guest
Jul 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. select extract(hour from e.dt_passagem) as hora,
  2. extract(day from e.dt_passagem) as dia,
  3. infracoes.qtde as infracao,
  4. count(e.id_estatistica) as volume,
  5. avg(e.vel_medida) as velocidademedia
  6.  
  7. from estatistica e
  8. left join (
  9. select extract(hour from r.dt_registro) as hora,
  10. extract(day from r.dt_registro) as dia,
  11. count(*) as qtde
  12. from registro r
  13. where r.id_tipo_infracao = 1 and
  14. (r.dt_registro between '2009-10-01 00:00:00' and '2009-10-31 23:59:59') and
  15. r.id_faixa = 46
  16. group by extract(hour from r.dt_registro),extract(day from r.dt_registro)
  17. order by extract(day from r.dt_registro),extract(hour from r.dt_registro)
  18. ) as infracoes
  19. on infracoes.dia = extract(day from e.dt_passagem) and
  20. infracoes.hora = extract(hour from e.dt_passagem)
  21.  
  22. where (e.dt_passagem between '2009-10-01 00:00:00' and '2009-10-31 23:59:59') and
  23. e.id_faixa = 46
  24.  
  25. group by extract(hour from e.dt_passagem),infracoes.qtde ,extract(day from e.dt_passagem)
  26. order by extract(day from e.dt_passagem)
Add Comment
Please, Sign In to add comment