Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/10/2018, 09:06
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: ¿Como hacer ésta consulta en SQL?

Código SQL:
Ver original
  1. SELECT t1.pacienteId FROM Movimiento_Paciente t1
  2. INNER JOIN Tratamiento t2 ON t1.pacienteId = t2.pacienteId
  3. INNER JOIN (SELECT MIN(fechaTratamiento) AS f_min, pacienteid FROM Tratamiento GROUP BY pacienteId) AS t3 ON (t3.pacienteid=t1.pacienteid)
  4. INNER JOIN (SELECT MIN(fechaInicio) f_min,pacienteid FROM Movimiento_Paciente GROUP BY pacienteId) AS t4 ON (t1.pacienteid=t4.pacienteid)
  5. WHERE t3.f_min<t4.f_min

Seria algo como eso :)
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me