Advertisement
armonge

Untitled

Dec 19th, 2011
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.70 KB | None | 0 0
  1. SELECT
  2. sc.id, u.telefono, sc.servicio_id,
  3. FROM mobi_suscripcion AS sc
  4. INNER JOIN mobi_usuariomovil AS u ON u.id = sc.usuario_id AND u."idEstado" = TRUE
  5. INNER JOIN mobi_servicio AS s ON sc.servicio_id = s.id
  6.  
  7. LEFT JOIN mobi_mensajemt AS mt ON mt.estado = 100 AND u.id = mt.usuario_id
  8. LEFT JOIN mobi_contenidomensaje AS co ON co.id = mt.contenido_id AND co.servicio_id = 23
  9. LEFT JOIN mobi_envio AS env ON env.id = mt.envio_id AND env.fecha_envio BETWEEN  '2011-12-19' AND '2011-12-19'
  10.  
  11. WHERE  sc.servicio_id = 23
  12. AND sc.estado = TRUE
  13. AND sc.fecha_suscripcion < '2011-12-19'
  14.  
  15. AND env.fecha_envio BETWEEN  '2011-12-19' AND '2011-12-19'
  16.  
  17. GROUP BY sc.id, u.id, s.id
  18. HAVING COUNT(mt.id) < s.max_mt_day;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement